【发布时间】:2017-02-22 11:46:05
【问题描述】:
我正在尝试从我的键盘扩展程序打开。我有自定义键盘,我已经从设置中添加了该键盘。在我的自定义键盘上,有一个“显示更多”按钮,我想在单击此按钮时打开我的应用程序。
所以我尝试了以下代码:
let context = NSExtensionContext()
context.open(url! as URL, completionHandler: nil)
var responder = self as UIResponder?
while (responder != nil) {
if responder?.responds(to: Selector("openURL:")) == true {
responder?.perform(Selector("openURL:"), with: url)
}
responder = responder!.next
}
它工作成功,但正如我们所知,Selector("method_name:") 已被弃用,而是使用#selector(classname.methodname(_:)),因此它会发出警告。我想解决这个警告。所以我尝试了 Xcode 自动建议的方法:
if responder?.responds(to: #selector(UIApplication.openURL(_:))) == true {
responder?.perform(#selector(UIApplication.openURL(_:)), with: url)
}
也试过了:
if responder?.responds(to: #selector(NSExtensionContext.open(_:))) == true {
responder?.perform(#selector(NSExtensionContext.open(_:)), with: url)
}
我也尝试了其他可能的方法,但没有运气。如果有人知道怎么做,请告诉我。
我参考了这个链接,Julio Bailon 的回答:
【问题讨论】:
-
找到解决方案了吗?
-
还没有……@Danny182
-
一些应用程序可以做到这一点。很奇怪 ???? @VRAwesome
-
你解决了这个问题吗?
-
那些是什么应用程序?你能说出一些吗?
标签: ios selector swift3 ios-app-extension custom-keyboard