我看到了有关该问题的一些帖子,但仍然听不懂。
我将URLidentifier设置为包含应用程序-KbrdApp。如果我的包含应用程序启动,它将返回标志“1”,表示“就绪”。
这是来自viewDidLoad
的自定义键盘扩展的代码:
UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
NSString *customURL = @"KbrdApp://";
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:customURL]];
[webView loadRequest:request];
我读过
NSExtensionContext
仅适用于Today扩展,因此我尝试了UIWebView
。但这是行不通的。怎么了?
最佳答案
问题中提到的方法已在iOS 8.0中停止工作。
当前(iOS 9.2),您可以使用多种方法来访问共享的UIApplication
实例及其隐藏的openURL
方法。
我个人更喜欢我开发的这种方法:
// Usage:
// UIApplication.🚀sharedApplication().🚀openURL(NSURL(string: "your-app-scheme://")!)
extension UIApplication {
public static func 🚀sharedApplication() -> UIApplication {
guard UIApplication.respondsToSelector("sharedApplication") else {
fatalError("UIApplication.sharedKeyboardApplication(): `UIApplication` does not respond to selector `sharedApplication`.")
}
guard let unmanagedSharedApplication = UIApplication.performSelector("sharedApplication") else {
fatalError("UIApplication.sharedKeyboardApplication(): `UIApplication.sharedApplication()` returned `nil`.")
}
guard let sharedApplication = unmanagedSharedApplication.takeUnretainedValue() as? UIApplication else {
fatalError("UIApplication.sharedKeyboardApplication(): `UIApplication.sharedApplication()` returned not `UIApplication` instance.")
}
return sharedApplication
}
public func 🚀openURL(url: NSURL) -> Bool {
return self.performSelector("openURL:", withObject: url) != nil
}
}