2

After INUIHostedViewControlling view controller is tapped, is there a way to send some arguments/URL to the app?

For example in Widget extension there is:

self.extensionContext?.open(cardURL, completionHandler: nil)
manikal
  • 953
  • 7
  • 30

1 Answers1

0

It seems like some extension types are more limited in their use of the extensionContext. I had the same problem with a keyboard extension. It might be a little hacky, but the code below worked for me.

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

As proposed by https://stackoverflow.com/a/44694703/2064473

Martin
  • 1,112
  • 1
  • 11
  • 31