Trying to use [self.extensionContext openURL:... completionHandler:...];
in an iOS 8 Share extension to open the containing app never opens the app, and always calls the completion handler with success = NO.
Here is the same issue with Action extensions, but I think it is more reasonable for Share extensions to be able to open the containing app than Action extensions. The point of a Share extension is to upload a potentially large piece of data, and the only way to do that without opening the app is through NSURLSession
, which can only do HTTP(S) uploads. But an app may wish to share content through a different mechanism than HTTP(S) uploads.
Apple documentation doesn't state that openURL...
cannot be used for any particular type of extension. It's hard to know whether this is a bug or intended behavior. There is no official information about this.
This is what I use from my keyboard extension. I hope it helps here too:
Please note that in this case I am instantiating this call from the UIInputViewController.
This method should also work using the URL scheme from the containing app
I'm using this method which does not involve any background task:
UIViewController
(instead of the defaultSLComposeServiceViewController
) subclass for share extension in order to add custom layout;UIWebView
and load an HTML string with a link pointing to your app's custom URL;webView:shouldStartLoadWithRequest:navigationType:
method to intercept the click on the link and before returning YES useNSUserDefaults
withinitWithSuiteName:
(providing the name of the app group) to save data in the container shared by your extension and the containing app.The click on the web link launches the app, which can fetch the data in
NSUserDefaults
directly.Here are some possible workarounds... Communicating with/opening Containing app from Share extension
The ones that actually work can be summed up as:
application:handleEventsForBackgroundURLSession:completionHandler:
method of the UIApplicationDelegate class of your container app to be called. Then, in that method, you can call[[UIApplication sharedApplication] openURL:url]
to open whatever you want.Neither of these methods are perfect, but they do work (not sure if Apple would like them though). For more details you can check out the link. Hope this helps :)
Edit: You can also use a UIWebView as described https://stackoverflow.com/a/24614589/3923882
The documentation does indicate that the "extension point determines whether to support this method" and in practice only those who use the Today Extension are able to launch their host app using openUrl. Share, Action, Keyboard, and Document provider do not work for anyone (beta 5).