IOS - 无法以编程方式打开 Whatsapp 聊天,但可以通过 HTML 进行

标签 ios swift whatsapp

我有一个带有 href="whatsapp:+(xxxxxxxxx)" anchor 的网页,如果我在我的 iPhone (iOS 9) 上点击它,它会在该联系人的聊天 View 中打开 WhatsApp(我可以查看我与联系人进行的所有聊天)。 但是,如果我以编程方式执行此操作(相同的 url),它只会在聊天选项卡上打开 WhatsApp。

我尝试过其他方法(使用地址簿 API,并使用“whatsapp://send?abid=RECORDID”),但都失败了。

任何帮助将不胜感激。

最佳答案

您应该将 WhatsApp URL 方案添加到您的应用程序 Info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>whatsapp</string>
</array>

根据 Apple Developer documentation

IMPORTANT If your app is linked on or after iOS 9.0, you must declare the URL schemes you want to pass to this method. Do this by using the LSApplicationQueriesSchemes array in your Xcode project’s Info.plist file. For each URL scheme you want your app to use with this method, add it as a string in this array.

If your (iOS 9.0 or later) app calls this method using a scheme you have not declared, the method returns NO, whether or not an appropriate app for the scheme is installed on the device.

关于IOS - 无法以编程方式打开 Whatsapp 聊天,但可以通过 HTML 进行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36066770/

相关文章:

swift - 是否可以(以编程方式)在 macOS 中为每个单独的 "space"/desktop 设置壁纸?

php - 如何使用 PHP 设置新​​的 Google Cloud Messaging API 服务器实现和托管?

ios - XCODE/IOS-通过直接打开将音频文件共享到whatsapp

angularjs - AngularJS 中的 Whatsapp 共享

ios - iOS 7 CoreData 中的批量更新数据

Plist 文件中的 iPhone UIColor

swift - 在 Swift 中从字符串中提取 float

ios - 如何在 Objective-C 中硬编码 .cer 证书?

iOS:NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error 会导致什么错误:

swift - (Swift) 无法仅检索视频 Assets 的路径