Ash*_*rma 1 ios instagram swift
我试图通过 UIButton 操作从我的 iOS 应用程序打开 Instagram 应用程序,但它不起作用。它什么也没显示。
这是我在 Swift 3 中的代码:
@IBAction func Instagram(_ sender: AnyObject) {
let instagramURL = URL(string: "instagram://app")!
if UIApplication.shared.canOpenURL(instagramURL) {
UIApplication.shared.openURL(instagramURL)
}
Run Code Online (Sandbox Code Playgroud)
对于 swift 4.2+ 和 ios 9+ 此代码启动 Instagram,如果未安装,请在网络浏览器中启动 Instagram 个人资料页面。
let screenName = "mehdico" // CHANGE THIS
let appURL = URL(string: "instagram://user?username=\(screenName)")
let webURL = URL(string: "https://instagram.com/\(screenName)")
if UIApplication.shared.canOpenURL(appURL) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(appURL, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(appURL)
}
} else {
//redirect to safari because the user doesn't have Instagram
if #available(iOS 10.0, *) {
UIApplication.shared.open(webURL, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(webURL)
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5305 次 |
最近记录: |