2

即使我已经将它添加到我的LSApplicationQueriesSchemes中,我总是会收到此响应

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
        <string>viber</string>
        <string>whatsapp</string>
    </array>

我像这样执行我的代码

let viberUrl = NSURL( string: "viber://forward?text=Hello")!

      if UIApplication.sharedApplication().canOpenURL(viberUrl) {
        print("app installed")
      }

和 xcode 日志:

-canOpenURL: failed for URL: "viber://" - error: "This app is not allowed to query for scheme viber"

我可以使用我的应用程序打开 viber 应用程序,但我也想测试该应用程序是否已安装。

任何线索我错在哪里?还是我错过了什么?我的测试设备 iphone 5s 和 iOS 9。

4

1 回答 1

0

尝试这样做

let mainViberUrl = NSURL(string: "viber://")!
let viberUrl = NSURL( string: "viber://forward?text=Hello")!

if UIApplication.sharedApplication().canOpenURL(mainViberUrl) {
    print("app installed")
    UIApplication.sharedApplication().openUrl(viberUrl)
}

我认为最好像我的代码那样做,因为forward?text=Hello"NSURL 的查询部分会产生一个错误,导致canOpenURL返回 false。

注意:这适用于我的顺便说一句

这是一个链接,可以帮助您更好地理解这个 http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl/

于 2017-01-16T02:17:06.693 回答