从其他应用程序启动Youtube应用程序无法在ios 9中运行

时间:2016-01-23 12:05:29

标签: ios objective-c youtube ios9

  if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"https://www.youtube.com/watch?v=VideoID"]]) {

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.youtube.com/watch?v=VideoID"]];
    }

输出: -canOpenURL:网址失败:" youtube://www.youtube.com/watch?v = UFccvtrP1d8" - 错误:"此应用不允许查询方案youtube"

1 个答案:

答案 0 :(得分:7)

试试这个

  

在iOS 9中,您必须将您的应用程序想要在LSApplicationQueriesSchemes键(字符串数组)下的Info.plist中查询的任何URL方案列入白名单:

将字符串添加为youtube

例如

<key>LSApplicationQueriesSchemes</key>
<array>
 <string>youtube</string>
   </array>
  

二次检查您的设备中是否有youtube应用

例如

 NSString *Name = @"VideoID";

NSURL *linkToApp = [NSURL URLWithString:[NSString stringWithFormat:@"youtube://watch?v=%@",Name]]; // I dont know excatly this one 
NSURL *linkToWeb = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.youtube.com/watch?v=%@",Name]]; // this is correct


if ([[UIApplication sharedApplication] canOpenURL:linkToApp]) {
    // Can open the youtube app URL so launch the youTube app with this URL
    [[UIApplication sharedApplication] openURL:linkToApp];
}
else{
    // Can't open the youtube app URL so launch Safari instead
    [[UIApplication sharedApplication] openURL:linkToWeb];
}

了解有关播放Youtube Video

的更多信息