Fah*_*kar 4 youtube objective-c youtube-channels ios
要在youtube应用上发布视频,我使用下面的代码.
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];
}
Run Code Online (Sandbox Code Playgroud)
现在客户改变了主意,并要求在iPhone应用程序中放置频道.
为了测试,我使用了链接http://www.youtube.com/user/richarddawkinsdotnet
但是当我使用这个链接,而不是YouTube应用程序,它总是在Safari中打开.:(
关于如何在提供链接的YouTube应用中打开频道的任何想法/建议?
Mar*_*ges 12
您的代码出错了,因为虽然您正在检查是否可以或多或少地正确打开youTube网址,但您只需打开一个网址,该网址将始终在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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4232 次 |
| 最近记录: |