How to send message and link to WhatsApp in Swift 3?

How to send message and link to WhatsApp in Swift 3

I am using this code: Code

Error message on console:

... failed url: "whatsapp: // send? text = Check" - error: "This app is not allowed to query for whatsapp scheme"

thank

+3


source to share


1 answer


You should try the following:

Note. The whatsapp app must be installed on your device.

Swift 3



var documentInteractionController: UIDocumentInteractionController = UIDocumentInteractionController()

@IBAction func whatsappShareText(_ sender: AnyObject)
{
    let originalString = "First Whatsapp Share"
    let escapedString = originalString.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed)

    let url  = URL(string: "whatsapp://send?text=\(escapedString!)")

    if UIApplication.shared.canOpenURL(url! as URL)
    {
        UIApplication.shared.open(url! as URL, options: [:], completionHandler: nil)
    }
}

@IBAction func whatsappShareLink(_ sender: AnyObject)
{
    let originalString = "https://www.google.co.in"
    let escapedString = originalString.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed)
    let url  = URL(string: "whatsapp://send?text=\(escapedString!)")

    if UIApplication.shared.canOpenURL(url! as URL)
    {
        UIApplication.shared.open(url! as URL, options: [:], completionHandler: nil)
    }
}

      

Add this code to your application "info.plist"

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

      

+7


source







All Articles