无法从小部件打开应用程序。 (使用URL)

时间:2017-01-13 03:13:31

标签: ios swift swift3 xcode8 today-extension

我试图在用户点按我的小部件时启动我的应用。

这是我的代码:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let myAppUrl = NSURL(string: "Sleep-Analysis")!
    extensionContext?.open(myAppUrl as URL, completionHandler: { (success) in
        if (!success) {
           print("error")            }
    })
}

但应用程序没有启动,但却给了我这个错误。

2017-01-13 09:36:23.921768 Sleep Timer Widget[10365:3109526] __55-[_NCWidgetExtensionContext openURL:completionHandler:]_block_invoke failed: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)"

我已经在项目的info.plist和info部分设置了URL方案。

我可能做错了什么,但这里是info.plist的截图

这是我的项目信息部分。

1 个答案:

答案 0 :(得分:2)

我认为URL字符串格式不正确。

试试这个:

extensionContext?.open(URL(string: "Sleep-Analysis://")!, completionHandler: { (success) in
            if (!success)
            {
                print("error")
            }
        })
相关问题