我想發送一個whatsapp消息到存儲在一個全局變量的收件人號碼!發送Whatsapp消息到一個特定的聯繫號碼(Swift項目)
通過這種簡單的代碼:
let whatsAppUrl = NSURL(string: "whatsapp:\(globalPhone)")
if UIApplication.shared.canOpenURL(whatsAppUrl as! URL) {
UIApplication.shared.openURL(whatsAppUrl as! URL)
}
else {
let errorAlert = UIAlertView(title: "Sorry", message: "You can't send a message to this number", delegate: self, cancelButtonTitle:"Ok")
errorAlert.show()
}
我總是得到警報消息的是在其他情況下! 雖然數字永遠是真的! 可能是url語法中的錯誤?
在控制檯:
canOpenURL: failed for URL: "whatsapp:0534260282" -
"This app is not allowed to query for scheme whatsapp"
這是做正確的方法是什麼? 或者這種方式只是爲了分享,通過WhatsApp的文字?
我已經做到了!但是我可以打開whatsapp應用程序而不是我要發送消息的收件人? – Mariah
如何將其直接發送給收件人? – Mariah
@Mariah根據他們的文檔:https://www.whatsapp.com/faq/en/iphone/23559013,它似乎並不可能,但是你可以指定文本。請參閱最新的答案。 –