How to share content on WhatsApp from iOS

前端 未结 3 1518
闹比i
闹比i 2021-01-20 02:12

I would like to share one Url link and some text message into WhatsApp from my application. How can i share content?

I got this code for only text

NS         


        
相关标签:
3条回答
  • 2021-01-20 02:42

    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

    0 讨论(0)
  • 2021-01-20 03:02

    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.
    0 讨论(0)
  • 2021-01-20 03:04

    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

    0 讨论(0)
提交回复
热议问题