How to share content on WhatsApp from iOS

旧街凉风 提交于 2019-12-01 21:03:23

Include the plain link inside the text, e.g.:

NSString * msg = @"Trueman India Magazine http://www.truemanindiamagazine.com";

The link will be generated/tappable after sending it to someone

I had a problem with this whatsapp api with url strings, especially when they contained a query string with several fields, e.g. http://example.com/foo?bar=foo&foo=bar. When opening the app I found the message text would be empty.

The solution was to properly percent escape the string using the CFString functions. See the apple documentation here: https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFURLRef/index.html#//apple_ref/c/func/CFURLCreateStringByAddingPercentEscapes

But for anyone else with this issue here is my solution in full:

CFStringRef originalURLString = (__bridge CFStringRef)[NSString stringWithFormat:@"%@", @"http://example.com/foo?bar=foo&foo=bar"];
CFStringRef preprocessedURLString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, originalURLString, CFSTR(""), kCFStringEncodingUTF8);
NSString *urlString = (__bridge NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, preprocessedURLString, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8);
NSString *whatsAppURLString = [NSString stringWithFormat:@"whatsapp://send?text=%@", urlString];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:whatsAppURLString]];
  • Note the use of the characters to be escaped in the CFURLCreateStringByAddingPercentEscapes function.

We can achieve this by using simple jquery. here is the article link http://www.stepblogging.com/how-to-share-web-article-on-whatsapp-using-jquery/

and you can check demo on your smart phone Demo Link

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!