ios - Sending message to WhatsApp from your app using Swift? -


for 1 of app, wanted share data whatsapp contacts. tried few solutions overs stackoverflow couldn't exact solution. after trials achieve looking for, sharing here anyone's future reference.

 var url  = nsurl(string: "whatsapp://send?text=hello%20friends%2c%20sharing%20some%20data%20here...%20!")  //text shared on whatsapp is: "hello friends, sharing data here... !"      if uiapplication.sharedapplication().canopenurl(url!) {         uiapplication.sharedapplication().openurl(url!)     } 

note: text needs url encoded. can using of open source tools on internet or using stringbyaddingpercentencodingwithallowedcharacters function in ios. e.g.

var urlstring = "hello friends, sharing data here... !" var urlstringencoded = urlstring.stringbyaddingpercentencodingwithallowedcharacters(.urlhostallowedcharacterset()) var url  = nsurl(string: "whatsapp://send?text=\(urlstringencoded!)") 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -