How to launch a parent iOS App from its App Extension

后端 未结 7 1368
借酒劲吻你
借酒劲吻你 2021-02-07 07:22

Does any one know how to launch the parent app from the app extension\'s view controller?

I just want to launch the main app from its app extension.

7条回答
  •  伪装坚强ぢ
    2021-02-07 07:33

    Working solution in Swift 3.1 (tested in iOS10):

    You need to create your own URL Scheme for your host app, 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
    }
    

提交回复
热议问题