在iOS 9中无法从其他应用启动YouTube应用 [英] Youtube application launch from other app is not working in ios 9
本文介绍了在iOS 9中无法从其他应用启动YouTube应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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:URL失败:"youtube://www.youtube.com/watch?v = UFccvtrP1d8"-错误:此应用程序不允许查询YouTube方案"
Output : -canOpenURL: failed for URL: "youtube://www.youtube.com/watch?v=UFccvtrP1d8" - error: "This app is not allowed to query for scheme youtube"
推荐答案
尝试一下
在iOS 9中,您必须在LSApplicationQueriesSchemes密钥(字符串数组)下的Info.plist中将您的应用程序要查询的所有URL方案列入白名单:
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>
再次检查youtube应用是否在您的设备中可用
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视频
for more information about play Youtube Video
这篇关于在iOS 9中无法从其他应用启动YouTube应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文