I am trying to send a message from my iOS app developed in Swift to a Whatsapp contact. But the specific contact does not get opened, instead all my contacts in whatsApp open up.
My code so far -
func messageViaWhatsApp (sender: AnyObject) {
let messageBody = "Hello"
let whatsURL = "whatsapp://send?text=\(messageBody)"
let whatsAppURL = NSURL(string: whatsURL.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!)
if UIApplication.sharedApplication().canOpenURL(whatsAppURL!)
{
UIApplication.sharedApplication().openURL(whatsAppURL!)
}
else
{
let alert = UIAlertView(title: "Sorry", message: "Your device does not have whatsApp installed ", delegate: nil, cancelButtonTitle: "OK")
}
}
Thanks for your help. XCode - 8.0, Swift 2.3