使用IntentsUI扩展中的URL打开应用

时间:2018-12-30 13:54:05

标签: ios swift siri sirikit sirishortcuts

点击INUIHostedViewControlling视图控制器后,是否可以向应用程序发送一些参数/ URL?

例如在Widget扩展中有:

self.extensionContext?.open(cardURL, completionHandler: nil)

1 个答案:

答案 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)
}

https://stackoverflow.com/a/44694703/2064473提议