I want to launch my containing app.
I tried using URL schemes.
The URL scheme launched the app from other places - so the problem is not there.
Looks like this object is nil:
self.extensionContext
thus i can't run this method:
[self.extensionContext openURL:url completionHandler:nil];
Can I launch my app? Do URL Schemes work in a custom keyboard?
thanks!
In an App Extension (ex: custom keyboard), that would have been handled through
UIViewController.extensionContext
but as of iOS 8.1.2, the field isnil
in the following Swift call:Actually, it is not possible either to use
Application.sharedApplication.openURL(...)
in an App Extension as stated in Apple documentation.So, as of 8.1.2, the workaround is to use a dumb
UIWebView
to redirect to the containing app like this:Where
MyKeyboard://
must be defined accordingly as URL scheme in the containing app.Please take note that I don't know yet whether this is approved by Apple. Forwarding to apps from custom keyboards may be bad enough for user experience.
To answer MY OWN question:
In an iOS8 custom keyboard, the extensionContext object is nil, thus I can't use it to launch the containing app.
The workaround I came up with is:
I'm not sure if Apple will allow this to happen, but it works now.
As per Apple review guidelines for Extension, it is now not advised to open external apps from the extension.
For reference please see apple review guidelines
Section 4.4.1
Here is working solution (tested on iOS 9.2) for Keyboard Extension. This category adds special method for access to hidden
sharedApplication
object and then callopenURL:
on it. (Of course then you have to useopenURL:
method with your app scheme.)Lately I developed slightly different approach:
A Swift 2.2 version, akin to DongHyun Jang's answer for Objective-C:
According to Apple's documentation https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/index.html, you should use NSExtensionContext like this: