openURL from App Extension

后端 未结 2 1214
孤独总比滥情好
孤独总比滥情好 2020-12-06 01:09

On iOS 8 beta 2 it should be possible to use openUrl from app extension as written into the release notes:

\"ent

相关标签:
2条回答
  • 2020-12-06 01:27

    you may use this code:

    [self.extensionContext openURL:url completionHandler:^(BOOL success) {
            NSLog(@"fun=%s after completion. success=%d", __func__, success);
        }];
    

    the API document: openURL:completionHandler:

    you could also refer to this question: openURL not work in Action Extension

    0 讨论(0)
  • 2020-12-06 01:30

    Accepted solution only works in Today extensions, a working solution in Swift 3.1 (tested in iOS10) for other extension-types:

    You need to create your own URL Scheme, then add this function to your ViewController and call it with 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
    }
    
    0 讨论(0)
提交回复
热议问题