加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift3 – 如何在Swift 3中发送消息并链接到WhatsApp?

发布时间:2020-12-14 04:51:00 所属栏目:百科 来源:网络整理
导读:如何在 Swift 3中发送消息并链接到WhatsApp 我正在使用此代码: ??Code 消息错误到控制台: …failed for URL: “whatsapp://send?text=Check” – error: “This app is not allowed to query for scheme whatsapp” 谢谢 解决方法 你应该试试这个: 注意:
如何在 Swift 3中发送消息并链接到WhatsApp

我正在使用此代码:
??Code

消息错误到控制台:

…failed for URL: “whatsapp://send?text=Check” – error: “This app is
not allowed to query for scheme whatsapp”

谢谢

解决方法

你应该试试这个:

注意:您必须在设备中安装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,completionHandler: nil)
    }
}

在您的应用“info.plist”中添加此代码

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读