I'm trying to send a whatsapp message to a recipient number stored in a global variable!
By using this simple code:
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()
}
I'm always getting the alert message which's the else case! although the number is always true! May be the the error in the url syntax?
In the console:
canOpenURL: failed for URL: "whatsapp:0534260282" -
"This app is not allowed to query for scheme whatsapp"
Is this the correct way to do that? Or this way just for sharing, text through Whatsapp?