![](/img/trans.png)
[英]How do I register my iOS app to open zip files from within the mail app in iOS 6+?
[英]How do I open Instagram app from my iOS app?
您在評論中發布的openUrl
方法在 iOS 10 中也已棄用
使用這個
@IBAction func openInstagramButtonPressed(_ sender: Any) {
let instagram = URL(string: "instagram://app")!
if UIApplication.shared.canOpenURL(instagram) {
UIApplication.shared.open(instagram, options: ["":""], completionHandler: nil)
} else {
print("Instagram not installed")
}
}
第一次它會提示您打開或取消。
還要確保為您已經完成的 instagram 執行LSApplicationQueriesSchemes
條目。
對於 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)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.