如果我得到一个 URL 是 youtube.com/watch?v=Hj57OP5C-ls .. 我应该在代码中添加什么?
- (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];
}
}
最佳答案
这样做:-)
- (IBAction)btnYoutube:(id)sender {
NSURL *linkToAppURL = [NSURL URLWithString:@"youtube://watch?v=Hj57OP5C-ls"];
NSURL *linkToWebURL = [NSURL URLWithString:@"https://www.youtube.com/watch?v=Hj57OP5C-ls"];
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];
}
}
关于ios - 我应该在超链接中添加什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35411401/