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];
}
Its working... tested...
Note
You cannot send whatsapp on specific number. That is disadvantage we have.
For sending whatsapp message on specific number, it can be done below way.
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?abid=1&text=Hello"];
^^^^
Try with this code.
abid
means Address Book ID. Now whatever is the number in your iPhone with id=1, it will choose this number.
The problem with abid
is that abid for that number is NOT same in all iPhone. Means in your iPhone abid=1 is 12345 but in my iPhone abid=1 is 34567.
Also if that number is not saved in iPhone, you cannot send whatsapp link on that number directly from iOS App.