Youtube application launch from other app is not working in ios 9

半城伤御伤魂 提交于 2019-12-23 01:52:14

问题


  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"]];
    }

Output : -canOpenURL: failed for URL: "youtube://www.youtube.com/watch?v=UFccvtrP1d8" - error: "This app is not allowed to query for scheme youtube"


回答1:


try this

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):

add string as youtube

for example

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

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

for example

 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];
}

for more information about play Youtube Video



来源:https://stackoverflow.com/questions/34963222/youtube-application-launch-from-other-app-is-not-working-in-ios-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!