Share link using whatsapp Share link using whatsapp ios ios

Share link using whatsapp


Add this to your Info.plist

<key>LSApplicationQueriesSchemes</key>    <array>        <string>whatsapp</string>    </array>

Implement this code to the ViewController where you need to open WhatsApp for sharing. (like for example say a button action)Update for swift 3 version (Xcode 8.x) : Updated for deprecations:

var str = "This is the string which you want to share to WhatsApp"str=str.addingPercentEncoding(withAllowedCharacters: (NSCharacterSet.urlQueryAllowed))!let whatsappURL = URL(string: "whatsapp://send?text=\(str)")if UIApplication.shared.canOpenURL(whatsappURL) {   UIApplication.shared.open(whatsappURL!, options: [:], completionHandler: nil)} else {   showAlert(message: "Whatsapp is not installed on this device. Please install Whatsapp and try again.")}

Here showAlert() is a custom function for showing an alert.


If you use "[[UIApplication sharedApplication] openURL: whatsappURL];" after string replcement it will open the safari browser not the whatsapp,

If you want to open whatsapp don't replace the string