Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share YouTube Link in WhatsApp

I am trying to share a YouTube link in Whats App with :

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 Whats App opens the message box is empty. Any idea why this happens?

like image 214
YosiFZ Avatar asked Aug 22 '13 09:08

YosiFZ


1 Answers

I found the answer if someone have 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);
like image 177
YosiFZ Avatar answered Oct 13 '22 00:10

YosiFZ