【问题标题】:Open containing app from custom keyboard in Swift 3?在 Swift 3 中从自定义键盘打开包含应用程序?
【发布时间】:2017-01-25 11:41:24
【问题描述】:

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

【问题讨论】:

    标签: swift custom-keyboard uiapplication


    【解决方案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")
    

    【讨论】:

      猜你喜欢
      • 2018-05-06
      • 2015-07-13
      • 1970-01-01
      • 2014-12-09
      • 2015-12-07
      • 1970-01-01
      • 1970-01-01
      • 2017-02-22
      • 2020-04-02
      相关资源
      最近更新 更多