示例代码:
let sampleURL = "http://Hello/site/link?id=MTk=&fid=MTA="
let urlWhats = "whatsapp://send?text=\(sampleURL)"
if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
if let whatsappURL = NSURL(string: urlString) {
if UIApplication.shared.canOpenURL(whatsappURL as URL) {
UIApplication.shared.open(whatsappURL as URL)
}
else {
// Open App Store.
}
}
}
添加在 .plist 文件中
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
面临的问题是在与&共享链接时没有在&之后出现文本
对于上面的 url 文本就像http://Hello/site/link?id=MTk=
提前致谢