Let's suppose that i have implemented an iOS web browser, capable of bidirectional communication with Javascript in the webview. What i would have to do if i wanted any iOS8 Action extensions to work in it, as it does in Mobile Safari? There is no problem in telling the webview to execute functions on the mandated ExtensionPreprocessingJS
object and get the callback result. But how do i even get hold of that NSExtensionJavaScriptPreprocessingFile
? I haven't found any iOS8 API which would allow me to enumerate the eligible app extensions. The less getting hold of their Info.plist
s and actually get the file out of the app extension's bundle content.
Through my test Action extension, i know that the whole extensionContext.inputItems
ever given to the extension is just and only what Apple Action extension doc says: a single NSItemProvider
under NSExtensionItemAttachmentsKey
, providing a single kUTTypePropertyList
with what the JS execution already returned. In other words, the JS must be known and executed even before beginRequestWithExtensionContext
is called.
Do i miss something or is it really impossible for 3rd party apps to do the same as Mobile Safari? It would make kind of sense from app access security point of view, but still... the keywords here are "modularity" and "extensibility", right? Is Mobile Safari treated a more equal animal than vanilla UI/WKWebView animals here? I mean, WKWebView
indeed has some neat new JS functionality (evaluate
completion handler, WKUserContentController
) but how do i wire it up with generic Action extension?
So, most likely, not possible. An Action extension can have NSExtensionActivationSupportsWebPageWithMaxCount
activation rule, which some sources claim is needed when you want to touch web pages with your extension. It wasn't needed for me, declaring NSExtensionJavaScriptPreprocessingFile
is enough. Anyway, nobody knows what is it that you would need to put to controller's activityItems
on the extension host side, the less what UTI it should be categorized with. I have tried
activityItems
array. This works nicely for "primitive" types like NSString
or NSURL
, despite missing UTIs. But for WKWebView
it results in runtime warning Unknown activity items supplied
.NSItemProvider
with the reference, guessing UTI with the most generic applicable kUTTypeContent
. XCode protests the technique already with semantic warning, because WKWebView
does not implement the required <NSSecureCopying>
protocol. Unsurprisingly, doesn't do anything.Last but not least, i found a Chromium feature request for exactly what i want to achieve. There a 1Password developer and a LastPass primary developer conclude that the level of app extension integration as in Mobile Safari isn't possible in 3rd party iOS web browsers.
Bummer.
If anyone wants to keep trying, i have rigged my iOS webview playground with the Activity code. Feel free to fork.