简体   繁体   English

如何从我的 iOS 应用程序打开 Instagram 应用程序?

[英]How do I open Instagram app from my iOS app?

I am trying to open the Instagram application from my iOS app through UIButton action but it's not working.我正在尝试通过 UIButton 操作从我的 iOS 应用程序打开 Instagram 应用程序,但它不起作用。 It shows nothing.它什么也没显示。

Here is my code in Swift 3:这是我在 Swift 3 中的代码:

@IBAction func Instagram(_ sender: AnyObject) {
    let instagramURL = URL(string: "instagram://app")!
    if UIApplication.shared.canOpenURL(instagramURL) {
        UIApplication.shared.openURL(instagramURL)
    }

这是我的 Plist 密钥 -

The method openUrl which you have posted in comments in deprecated too in iOS 10您在评论中发布的openUrl方法在 iOS 10 中也已弃用

Use this使用这个

@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")
    }
}

For the first time it will prompt you to open or cancel.第一次它会提示您打开或取消。

Also make sure to do the LSApplicationQueriesSchemes entry for instagram which you had already done.还要确保为您已经完成的 instagram 执行LSApplicationQueriesSchemes条目。

For swift 4.2+ and ios 9+ This code launch Instagram, if it's not installed, launch the Instagram profile page in a web browser.对于 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.

相关问题 如何在iOS 6+的邮件应用程序中注册我的iOS应用程序以打开zip文件? - How do I register my iOS app to open zip files from within the mail app in iOS 6+? 是否可以通过深层链接从 instagram 打开我的 iOS 应用程序? - Is it possible to open my iOS app from instagram through a deeplink? 如何使用我的ios应用程序提供的图像打开Instagram应用程序? - How to open the Instagram application with an image provided by my ios app? iOS:如何在我的应用程序中打开Facebook App中的特定帖子? - iOS: How do I open a specific post in the Facebook App from within my application? 如何从另一个iOS应用程序打开Thursby SubRosa? - How do I open Thursby SubRosa from another iOS App? 如何在iOS 9中通过我的应用程序打开Goog​​le Maps应用程序? - How do I open google maps app via my app in iOS 9? 如何让我的应用程序显示在 iOS 文件应用程序中 CSV 文件的打开菜单中? - How do I get my app to show up in the open in menu for a CSV file in the files app on iOS? 如何从我的应用程序打开ios Native拨号器应用程序 - How to open the ios Native dialer app from my App 如何从我的PhoneGap应用程序打开另一个iOS应用程序? - How to open another iOS app from my PhoneGap app? 如何从我的ios应用程序打开VK应用程序 - How to open VK app from my ios app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM