2016-10-25 110 views
2

我總是得到這個反應甚至我已經把它添加到我的LSApplicationQueriesSchemescanOpenURL:總是失敗

<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應用程序,但我也想要測試應用程序是否安裝。

任何線索我在哪裏弄錯了?或者我錯過了什麼? 我與iOS 9

回答

0

嘗試測試設備的iPhone 5S做這樣

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。

注:這適用於礦山BTW

這裏有一個鏈接可以幫助你更好的理解這個 http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl/