Ios 在youtube应用程序中启动youtube频道
为了在youtube应用程序上发布视频,我使用以下代码Ios 在youtube应用程序中启动youtube频道,ios,objective-c,youtube,youtube-channels,Ios,Objective C,Youtube,Youtube Channels,为了在youtube应用程序上发布视频,我使用以下代码 NSURL *instagramURL = [NSURL URLWithString:@"youtube://foo"]; if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) { NSLog(@"opening youtube app..."); NSString *stringURL = @"http://www.youtube.com/watc
NSURL *instagramURL = [NSURL URLWithString:@"youtube://foo"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
NSLog(@"opening youtube app...");
NSString *stringURL = @"http://www.youtube.com/watch?v=H9VdapQyWfg";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
} else {
// open in UIWebView in WebViewViewController
WebViewViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:@"webinterface"];
secondView.headerLabel = @"YouTube";
secondView.webPath = @"http://www.youtube.com/watch?v=H9VdapQyWfg";
[self.navigationController pushViewController:secondView animated:YES];
}
现在,客户改变主意,要求在iPhone应用程序中设置频道
为了测试,我使用了link
但当我使用此链接时,而不是youtube应用程序,它总是在SAFARI中打开(
关于如何使用提供的链接在YouTube应用程序中打开频道,有什么想法/建议吗?您的代码出错了,因为尽管您正在检查是否可以或多或少正确打开YouTube URL,但您只是打开了一个网址,该网址将始终在Safari中打开 这是我刚刚使用的代码,它对我有效。如果您想退回到使用webviewcontroller,可能需要修改else语句,因为如果未安装youtube应用程序,这将打开Safari
NSString *channelName = @"TheNameOfTheChannel";
NSURL *linkToAppURL = [NSURL URLWithString:[NSString stringWithFormat:@"youtube://user/%@",channelName]];
NSURL *linkToWebURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.youtube.com/user/%@",channelName]];
if ([[UIApplication sharedApplication] canOpenURL:linkToAppURL]) {
// Can open the youtube app URL so launch the youTube app with this URL
[[UIApplication sharedApplication] openURL:linkToAppURL];
}
else{
// Can't open the youtube app URL so launch Safari instead
[[UIApplication sharedApplication] openURL:linkToWebURL];
}
答案相同,但较短:
if (![[UIApplication sharedApplication] openURL: [NSURL URLWithString: @"youtube://user/%channelName%"]]) {
NSURL *webURL = [NSURL URLWithString:@"http://www.youtube.com/user/%channelName%"];
[[UIApplication sharedApplication] openURL: webURL];
}
和推特:
if (![[UIApplication sharedApplication] openURL: [NSURL URLWithString: @"twitter://user?screen_name=%channelName%"]]) {
NSURL *webURL = [NSURL URLWithString:@"http://twitter.com/%channelName%"];
[[UIApplication sharedApplication] openURL: webURL];
}
下面是更详尽的应用程序列表:
youtube://user/
在iOS 9中停止工作,因此我研究发现它现在在iOS 9中运行良好
youtube://www.youtube.com/channel/
我会检查此项并返回给您…我从未找到此答案..希望这能起作用…:D:p这对我不起作用!它只会转到应用程序的视频页面并显示“播放错误点击重试”,但在safari中打开时效果良好。如果您想在本机应用程序中打开URL,您应该这样使用:NSURL*linkToAppURL=@"youtube://www.youtube.com/user/%@,channelName];……以下方案将不起作用NSURL*linkToAppURL=@youtube://user/%@“,channelName];是否有打开特定视频的方法?