在Swift 3中打开包含自定义键盘的应用程序?

时间:2016-08-26 10:07:41

标签: swift custom-keyboard uiapplication

在iOS 10之前,我使用了Valentin Sherwin编写的方法here 使用Swift 3从自定义键盘打开包含应用程序的任何变通方法?

1 个答案:

答案 0 :(得分:1)

请尝试使用以下方法。 它在xcode 8.2,swift 3.0上运行良好

func openURL(_ url: URL) {
    return
}

func openApp(_ urlstring:String) {

    var responder: UIResponder? = self as UIResponder
    let selector = #selector(openURL(_:))
    while responder != nil {
        if responder!.responds(to: selector) && responder != self {
            responder!.perform(selector, with: URL(string: urlstring)!)
            return
        }
        responder = responder?.next
    }
}

// Usage
//call the method like below
// self.openApp(urlString)

// URL string need to included custom scheme.
// for example, if you created scheme name = customApp
// urlString will be "customApp://?[name]=[value]"
// self.openApp("customApp://?category=1")