如何在Swift 3中发送消息并链接到WhatsApp
我正在使用此代码: 代码
消息错误到控制台:
...网址失败:"whatsapp:// send?text = Check" - 错误:"此应用不允许查询方案whatsapp"
谢谢
Pra*_*ani 14
你应该试试这个:
注意:您必须在设备中安装whatsapp app.
斯威夫特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)
}
}
Run Code Online (Sandbox Code Playgroud)
在您的应用"info.plist"中添加此代码
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7357 次 |
| 最近记录: |