打开Instagram本地链接

Luc*_*nto 8 facebook objective-c instagram

要打开Facebook Native配置文件,我可以使用:

NSURL *url = [NSURL URLWithString:@"fb://profile/<id>"];
[[UIApplication sharedApplication] openURL:url];
Run Code Online (Sandbox Code Playgroud)

有什么方法可以为Instagram个人资料做同样的事情吗?

Dip*_*ara 26

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

目标C.

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

迅速

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

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")
    })
}
Run Code Online (Sandbox Code Playgroud)

如果您想了解更多有关它的详细信息,请参阅文档链接