我想在我的应用程序中打开一个whatsapp url.
let whatsAppUrl = NSURL(string: "whatsapp://send?text=Hello%2C%20World!")
if UIApplication.sharedApplication().canOpenURL(whatsAppUrl!) {
UIApplication.sharedApplication().openURL(whatsAppUrl!)
}
Run Code Online (Sandbox Code Playgroud)
我使用字典"LSApplicationQueriesSchemes"扩展我的info.plist并为whatsapp添加我的url方案.
<key>LSApplicationQueriesSchemes</key>
<dict>
<key>Item 0</key>
<string>whatsapp</string>
</dict>
Run Code Online (Sandbox Code Playgroud)
如果我运行我的应用程序,我收到以下错误消息.
"This app is not allowed to query for scheme whatsapp"
Run Code Online (Sandbox Code Playgroud)
我阅读了一些清理派生数据的解决方案并再次运行应用程序以解决此问题.但这对我没有帮助,对我的问题存在另一种解决方案吗?
您已经将LSApplicationQueriesSchemes设为a dict,它必须是一个数组,就像这样,然后它将工作:).
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
Run Code Online (Sandbox Code Playgroud)
我还建议你不要打开可选的URL !,你可以这样做:
guard
let whatsAppUrl = URL(string: "whatsapp://send?text=Hello%2C%20World!"),
case let application = UIApplication.shared,
application.canOpenURL(whatsAppUrl)
else { return }
application.openURL(whatsAppUrl)
Run Code Online (Sandbox Code Playgroud)
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)
}
}}
Run Code Online (Sandbox Code Playgroud)
并定义这样的查询方案
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5461 次 |
| 最近记录: |