My client has an iPad app that runs a web app in a WkWebView. The web app streams video using the MediaSource API, which is available on iPad and Mac but not iPhone. When running the app on Mac using Mac Catalyst, the MediaSource API is logged as not available – probably because Mac Catalyst builds with the iOS SDK.
I’ve tried running the same web app in a MacOS WKWebView in a pure Mac app, which worked.
I’m wondering if it’s possible to somehow use the MacOS WKWebView rather than the iOS WKWebView when the app is run using Mac Catalyst? Or if anybody has alternative solutions.
I’ve tried different solutions from forums, like wrapping a NSViewRepresentable around a WKWebView and including the Dynamic framework to access AppKit on Mac Catalyst, but this has failed, or XCode says it can’t access the elements I’m trying to use.
2
Answers
It should be possible to implement a macOS WKWebView from within an AppKit bundle. I’ve implemented several features of my maccatalyst app using this technique, including Sparkle update manager, registration dialogs, and other macOS windows. An AppKit plugin bundle begins with creating a Frameworks & Library Bundle target:
An article by Eskil Gjerde Sviggum that I found very useful.
I also found Conrad Stoll’s article helpful.
It’s not possible, even if you try to use WKWebView from an AppKit plug-in. WKWebView is one of those shared macOS/iOS classes that will cause a "conflict" and potentially a runtime crash; it’s only possible to use it from the iOS side of your app (from my experience).