【问题标题】:Cannot open app from widget. (using URL)无法从小部件打开应用程序。 (使用网址)
【发布时间】:2017-01-13 03:13:31
【问题描述】:

当用户点击我的小部件时,我正在尝试启动我的应用程序。

这是我的代码:

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 的屏幕截图

这是我的项目信息部分。

【问题讨论】:

  • 你找到问题了吗?我目前遇到完全相同的问题:(

标签: ios swift swift3 xcode8 today-extension


【解决方案1】:

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

试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多