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

标签 swift custom-keyboard uiapplication

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

最佳答案

请尝试使用以下方法。 它在 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")

关于swift - 从 Swift 3 中的自定义键盘打开包含应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39163735/

相关文章:

ios - 检查来自 Alamofire 和 Swift 的多个异步响应

objective-c - 自定义键盘崩溃共享库事件(内存泄漏?)

ios - 错误——Command/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc 失败,退出代码为 1

'Storage and iCloud Usage' 的 iOS 9 应用启动 URL

ios - 为什么在 iOS 11 中,我的 UIApplicationState 显示为非事件状态而不是事件状态?

ios - 我的应用程序中需要核心数据吗?

swift - 晦涩的问题,Google AdMob SDK,XCode 8.2 + Cocoapods 集成

swift - 扩展 ReactiveCocoa

ios - 如何检测当前用于文本输入的自定义键盘(ios 8)