我的iPhone上运行了我的应用程序,我可以从我的应用程序向WhatsApp发送一些数据。我通过以下方式做同样的事情:
Sending message to WhatsApp from your app using Swift?
我们是否有办法创建一个可以直接打开我们自己的应用程序的URL?有人可以建议我能理解如何做到的地方吗?
答案 0 :(得分:1)
这样的事情应该有效:
let originalString = "Some text you want to send"
let encodedString = originalString.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)
let url = NSURL(string: "whatsapp://send?text="+encodedString!)
if UIApplication.sharedApplication().canOpenURL(url!) {
UIApplication.sharedApplication().open(url as URL, options: [:]) { (success) in
if success {
print("WhatsApp accessed successfully")
} else {
print("Error accessing WhatsApp")
}
}
} else {
print("whatsapp not installed")
}