打开Instagram本地链接

时间:2013-05-04 01:50:08

标签: objective-c facebook instagram

要打开Facebook Native个人资料,我可以使用:

NSURL *url = [NSURL URLWithString:@"fb://profile/<id>"];
[[UIApplication sharedApplication] openURL:url];

有没有办法为Instagram个人资料做同样的事情?

1 个答案:

答案 0 :(得分:26)

以下代码段将使用userName在您的设备上打开Instagram应用。

目标C

NSURL *instagramURL = [NSURL URLWithString:@"instagram://user?username=USERNAME"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    [[UIApplication sharedApplication] openURL:instagramURL];
}

<强>夫特

var instagramURL: NSURL = NSURL(string: "instagram://user?username=USERNAME")
if UIApplication.sharedApplication().canOpenURL(instagramURL) {
    UIApplication.sharedApplication().openURL(instagramURL)
}

Swift 3.0

let instagramURL:URL = URL(string: "instagram://user?username=USERNAME")!
if UIApplication.shared.canOpenURL(instagramURL) {
    UIApplication.shared.open(instagramURL, options:[:], completionHandler: { (Bool) in
        print("Completion block")
    })
}

如果您想了解更多详细信息,可以参考Documentation link