如何在Swift 3中发送消息并链接到WhatsApp
我正在使用此代码: Code
消息错误到控制台:
...网址失败:“whatsapp:// send?text = Check” - 错误:“此应用是 不允许查询方案whatsapp“
谢谢
答案 0 :(得分:12)
你应该试试这个:
注意:您必须在设备中安装whatsapp app。
Swift 3
var documentInteractionController: UIDocumentInteractionController = UIDocumentInteractionController()
@IBAction func whatsappShareText(_ sender: AnyObject)
{
let originalString = "First Whatsapp Share"
let escapedString = originalString.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed)
let url = URL(string: "whatsapp://send?text=\(escapedString!)")
if UIApplication.shared.canOpenURL(url! as URL)
{
UIApplication.shared.open(url! as URL, options: [:], completionHandler: nil)
}
}
@IBAction func whatsappShareLink(_ sender: AnyObject)
{
let originalString = "https://www.google.co.in"
let escapedString = originalString.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed)
let url = URL(string: "whatsapp://send?text=\(escapedString!)")
if UIApplication.shared.canOpenURL(url! as URL)
{
UIApplication.shared.open(url! as URL, options: [:], completionHandler: nil)
}
}
在您的应用“info.plist”
中添加此代码<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
答案 1 :(得分:0)