ios - 我应该在超链接中添加什么?

标签 ios objective-c xcode hyperlink

如果我得到一个 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/

相关文章:

ios - 跳过应用程序验证 - 在归档应用程序以供提交时

ios - Apple 收据设备哈希验证

objective-c - 是否可以通过电子邮件发送 UIView?

ios - JSON 和 iPhone TableView

objective-c - 将 NSDecimalNumber 转换为 NSString

c# - 输出排序列表内容

ios - 移动屏幕外的 Storyboard元素

ios - 应用内购买在发布近一周后仍无法正常工作

ios - 从控制台发布 NSNotification

ios - [登录 View Controller View Controller ] : unrecognized selector sent to instance 0x10942c3d0