【发布时间】:2014-06-22 22:21:53
【问题描述】:
在 iOS 8 beta 2 上,应该可以使用写在发行说明中的应用扩展中的 openUrl:
但是,当我尝试使用此 API(在 Xcode 6 beta 2 上)时,我收到以下错误:
Beta 2 是否真的解决了这个问题?
【问题讨论】:
标签: ios8 uiapplication openurl ios-app-extension
在 iOS 8 beta 2 上,应该可以使用写在发行说明中的应用扩展中的 openUrl:
但是,当我尝试使用此 API(在 Xcode 6 beta 2 上)时,我收到以下错误:
Beta 2 是否真的解决了这个问题?
【问题讨论】:
标签: ios8 uiapplication openurl ios-app-extension
您可以使用此代码:
[self.extensionContext openURL:url completionHandler:^(BOOL success) {
NSLog(@"fun=%s after completion. success=%d", __func__, success);
}];
API 文档: openURL:completionHandler:
你也可以参考这个问题: openURL not work in Action Extension
【讨论】:
接受的解决方案仅适用于 Today extensions,这是 Swift 3.1(在 iOS10 中测试)中适用于其他扩展类型的有效解决方案:
您需要创建自己的 URL Scheme,然后将此函数添加到您的 ViewController 并使用 openURL("myScheme://myIdentifier") 调用它
// Function must be named exactly like this so a selector can be found by the compiler!
// Anyway - it's another selector in another instance that would be "performed" instead.
func openURL(_ url: URL) -> Bool {
var responder: UIResponder? = self
while responder != nil {
if let application = responder as? UIApplication {
return application.perform(#selector(openURL(_:)), with: url) != nil
}
responder = responder?.next
}
return false
}
【讨论】: