【问题标题】:Unable to send youtube video link to whats app as text message无法将 youtube 视频链接作为短信发送到 whats 应用程序
【发布时间】:2013-11-21 12:41:17
【问题描述】:

当链接包含视频 ID 时,代码可以与其他链接一起正常工作,但不适用于 youtube 链接...

    NSString*str=[NSString stringWithFormat:@"http://youtube.com/watch?v=%@",myVideoId];

    NSString*Wastring2=[ NSString stringWithFormat:@"whatsapp://send?text=%@",str];

    NSURL *whatsappURL =  [NSURL URLWithString:Wastring2];

    if ([[UIApplication sharedApplication] canOpenURL: [whatsappURL absoluteURL]]) {
         [[UIApplication sharedApplication] openURL: [whatsappURL absoluteURL]];
    }

谢谢。

【问题讨论】:

    标签: ios iphone ios5 url-scheme


    【解决方案1】:

    尝试对您的 youtube 网址进行编码。

      NSString*str=[NSString stringWithFormat:@"http://youtube.com/watch?v%3D%@",myVideoId];
    

    【讨论】:

    • " youtube.com/watch?v=id " 如果我​​删除 " = " 符号,那么它可以工作
    • NSLog 的 NSLog 是什么?
    • 如果只有 = 有问题,请尝试将 = 替换为 %3D,请参阅我编辑的答案。看起来 stringByAddingPercentEscapesUsingEncoding 实际上只是替换了空格和几个字符
    【解决方案2】:

    好的,我已经测试了 youtube 链接,现在它可以与下面的代码一起使用,您只需将百分比转义 ?v= 添加到 ?v%%3D

    注意必须有两个 %% 才能手动转义字符串

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-03
      • 2017-10-12
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多