我想打开一个whatsapp的网址在我的应用程序喜欢。
let whatsAppUrl = NSURL(string: "whatsapp://send?text=Hello%2C%20World!")
if UIApplication.sharedApplication().canOpenURL(whatsAppUrl!) {
UIApplication.sharedApplication().openURL(whatsAppUrl!)
}我用字典"LSApplicationQueriesSchemes“扩展了我的info.plist,并添加了我的whatsapp的url方案。
<key>LSApplicationQueriesSchemes</key>
<dict>
<key>Item 0</key>
<string>whatsapp</string>
</dict>如果我运行我的应用程序,我得到以下错误消息。
"This app is not allowed to query for scheme whatsapp"我阅读了一些关于清理派生数据的解决方案,并再次运行应用程序来解决此问题。但这对我没有帮助,有没有别的办法来解决我的问题?
发布于 2016-07-15 18:06:17
您已经将LSApplicationQueriesSchemes设为dict,它的必须是一个数组,就像this一样,然后它就可以工作了:)。
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>我也建议你不要使用!来解包可选的网址,你可以这样做:
guard
let whatsAppUrl = URL(string: "whatsapp://send?text=Hello%2C%20World!"),
case let application = UIApplication.shared,
application.canOpenURL(whatsAppUrl)
else { return }
application.openURL(whatsAppUrl)发布于 2016-07-15 18:28:04
let url = "whatsapp://send?text=Hello World!"
if let urlString = url.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) {
if let whatsappURL = NSURL(string: urlString) {
if UIApplication.sharedApplication().canOpenURL(whatsappURL) {
UIApplication.sharedApplication().openURL(whatsappURL)
}
}}并定义这样的查询方案
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>https://stackoverflow.com/questions/38393266
复制相似问题