gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:54:54 25 4
gpt4 key购买 nike

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

我正在使用这段代码: Code

向控制台发送错误消息:

...failed for URL: "whatsapp://send?text=Check" - error: "This app is not allowed to query for scheme whatsapp"

谢谢

最佳答案

你应该尝试这个:

注意:您的设备中必须安装有 Whatsapp 应用程序。

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>

关于swift3 - 如何在 Swift 3 中发送消息并链接到 WhatsApp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45111852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com