在WhatsApp中分享YouTube链接

MTA*_*MTA 7 iphone objective-c ios whatsapp

我想在Whats App中分享YouTube链接:

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

但是当Whats App打开时,消息框为空.知道为什么会这样吗?

MTA*_*MTA 3

如果有人遇到同样的问题,我找到了答案:

您只需要对 url 进行编码:

NSString *str = [NSString stringWithFormat:youTubeLink,videoId];

str = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
                                                            (CFStringRef)str,
                                                            NULL,
                                                            CFSTR("!*'();:@&=+$,/?%#[]"),
                                                            kCFStringEncodingUTF8);
Run Code Online (Sandbox Code Playgroud)