gpt4 book ai didi

ios - 如何从 Swift 应用程序打开 WhatsApp?

转载 作者:可可西里 更新时间:2023-10-31 23:51:50 25 4
gpt4 key购买 nike

我正在为我的 Swift 应用程序使用 webview 并且我的网站上有“在 WhatsApp 上分享”按钮,它在浏览器上运行良好。但是在 iPhone 应用程序上,当我点击按钮时,没有任何反应。

如何从我的应用程序打开 WhatsApp?我正在使用 Xcode 8 和 iOS 10。

最佳答案

适用于 Swift 4.2+ 和 iOS 9+

方法 1:(启动 WhatsApp 应用程序,如果已安装)

let phoneNumber =  "+989160000000" // you need to change this number
let appURL = URL(string: "https://api.whatsapp.com/send?phone=\(phoneNumber)")!
if UIApplication.shared.canOpenURL(appURL) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(appURL, options: [:], completionHandler: nil)
}
else {
UIApplication.shared.openURL(appURL)
}
}

方法二:(使用safari打开WhatsApp短链接网页)

let phoneNumber =  "+989160000000" // you need to change this number
let appURL = URL(string: "https://wa.me/\(phoneNumber)")!
if UIApplication.shared.canOpenURL(appURL) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(appURL, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(appURL)
}
}

注意:电话号码中的“+”即可。

关于ios - 如何从 Swift 应用程序打开 WhatsApp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39809620/

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