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

ram*_*ram 1 youtube objective-c ios 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"]];
    }
Run Code Online (Sandbox Code Playgroud)

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

Anb*_*hik 7

试试这个

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

添加字符串为 youtube

例如

<key>LSApplicationQueriesSchemes</key>
<array>
 <string>youtube</string>
   </array>
Run Code Online (Sandbox Code Playgroud)

二次检查您的设备中是否有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];
}
Run Code Online (Sandbox Code Playgroud)

有关播放Youtube视频的更多信息