Share YouTube WhatsApp Link

I am trying to share a YouTube link in a Whats app using:

NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=http://www.youtube.com/watch?v=lWA2pjMjpBs"]; if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) { [[UIApplication sharedApplication] openURL: whatsappURL]; } 

But when the Whats application opens, the message box is empty. Any idea why this is happening?

+7
ios objective-c iphone whatsapp
source share
4 answers

I found the answer if someone has the same problem:

You just need to encode the url:

 NSString *str = [NSString stringWithFormat:youTubeLink,videoId]; str = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)str, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8); 
+3
source share

For encoding use below.

 NSString *str = [NSString stringWithFormat:@"http://www.youtube.com/watch?v=lWA2pjMjpBs" ]; str = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *whatsappURL = [NSURL URLWithString:[NSString stringWithFormat:@"whatsapp://send?text=%@", str]]; if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) { [[UIApplication sharedApplication] openURL: whatsappURL]; } 

His work ... verified ...

Note

You cannot send whatsapp to a specific number. This is the flaw that we have.

To send whatsapp messages to a specific number, this can be done below.

 NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?abid=1&text=Hello"]; ^^^^ 

Try this code.

abid means the address book identifier. Now, whatever your iPhone number is with id = 1, it will select that number.

The problem with abid is that abid for this number is NOT ONLY on all iPhone. The funds in your iPhone abid = 1 - 12345, but in my iPhone abid = 1 - 34567.

Also, if this number is not saved on the iPhone, you cannot send the whatsapp link to this number directly from the iOS application.

+1
source share
 str = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)str, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8)); 
+1
source share

I know this is an old post, but did not find an acceptable answer to the question, so I am posting my answer. This can sometimes help someone.

In my application, I tried to split the AppStore link of my application through WhatsApp. But WhatsApp opens the message box as empty. So I tried to send the link after encoding the link, believing that WhatsApp blocks the link because it contains special characters. But that didn't work for me either.

Finally, I found a solution by shortening the link using Bitly . You can create a short link for any links using Bitly and you can share these links with WhatsApp without any problems.

+1
source share

All Articles