点击INUIHostedViewControlling
视图控制器后,是否可以向应用程序发送一些参数/ URL?
例如在Widget扩展中有:
self.extensionContext?.open(cardURL, completionHandler: nil)
答案 0 :(得分:0)
似乎某些扩展类型在使用extensionContext时受到更多限制。键盘扩展名也有同样的问题。可能有点hacky,但是下面的代码对我有用。
func openUrl(url: URL?) {
let selector = sel_registerName("openURL:")
var responder = self as UIResponder?
while let r = responder, !r.responds(to: selector) {
responder = r.next
}
_ = responder?.perform(selector, with: url)
}
func canOpenUrl(url: URL?) -> Bool {
let selector = sel_registerName("canOpenURL:")
var responder = self as UIResponder?
while let r = responder, !r.responds(to: selector) {
responder = r.next
}
return (responder!.perform(selector, with: url) != nil)
}