2016-01-23 82 views
0
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"]]; 
    } 

输出工作 “的YouTube://www.youtube.com/watch V = UFccvtrP1d8?” - 错误:“此应用程序是不允许查询计划的YouTube”的Youtube应用程序启动未在IOS 9

+0

你为什么要检查'canOpenURL'更多信息?只需打开网址即可。 – luk2302

+0

我只需要在youtube应用程序中打开。你可以帮忙吗?我想在其他部分做其他情况 – ram

+0

天气它正在工作ios 9 – ram

回答

6

试试这个

In iOS 9 you must whitelist any URL schemes your App wants to query in Info.plist under the LSApplicationQueriesSchemes key (an array of strings):

添加字符串作为youtube

例如

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

secondary check that the youtube app is available or not in your device

例如

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