我从互联网上为Xcode添加了一段代码。
这一个:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com"]];
我在Safari浏览器上访问了www.youtube.com,如果我有youtube应用程序怎么办?怎么能从iPhone中的应用程序打开它?
p.s我是新手
答案 0 :(得分:2)
- (IBAction)btnYoutube:(id)sender {
NSURL *linkToAppURL = [NSURL URLWithString:[NSString stringWithFormat:@"youtube://user/%@",@"toyotaleasing"]];
NSURL *linkToWebURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.youtube.com/user/%@",@"toyotaleasing"]];
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];
}
}
答案 1 :(得分:0)
使用youtube的网址方案: youtube://
例如
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"youtube://www.youtube.com/watch?v=<video-id>"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"youtube://www.youtube.com/watch?v=<video-id>"]];
}
希望,它会帮助你。