iOS 9 not opening Instagram app with URL SCHEME

后端 未结 14 1893
攒了一身酷
攒了一身酷 2020-11-22 06:33

The following URL opens on iOS 8.3 and lower, but it does not work and iOS 9

let instagramURL = NSURL(string: \"instagram://app\")

Why won\

相关标签:
14条回答
  • 2020-11-22 07:14

    Swift 3.1, Swift 3.2, Swift 4

    if let urlFromStr = URL(string: "instagram://app") {
        if UIApplication.shared.canOpenURL(urlFromStr) {
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(urlFromStr, options: [:], completionHandler: nil)
            } else {
                UIApplication.shared.openURL(urlFromStr)
            }
        }
    }
    

    Add these in Info.plist :

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>instagram</string>
    </array>
    
    0 讨论(0)
  • 2020-11-22 07:17

    As said above, you want to add a key in the info plist, here is the list for most social networks

    <key>LSApplicationQueriesSchemes</key>
        <array>
         <string>fb</string>
         <string>fbapi</string>
         <string>fbauth2</string>
         <string>fbshareextension</string>
         <string>fb-messenger-api</string>
         <string>twitter</string>
         <string>viber</string>
         <string>whatsapp</string>
         <string>wechat</string>
         <string>line</string>
         <string>instagram</string>
         <string> instagram-stories</string>
         <string>kakaotalk</string>
         <string>mqq</string>
         <string>vk</string>
         <string>comgooglemaps</string>
         <string>googlephotos</string>
         <string>ha</string>
         <string>yammer</string>
        </array>
    

    * The first 3 match Facebook (FBSDK 4.6): fbapi, fbauth2, fbshareextension. "Ha" is for snapchat

    0 讨论(0)
  • 2020-11-22 07:17

    Apple changed the canOpenURL method on iOS 9. Apps which are checking for URL Schemes on iOS 9 and iOS 10 have to declare these Schemes as it is submitted to Apple.

    0 讨论(0)
  • 2020-11-22 07:21

    It doesn't seem anyone has addressed how to specify URLs with embedded parameters. Any URL that contains parameters it won't possible to specify the specific URL in LSApplicationsQueriesSchemes. For example, assume I have an email app that passes the the senders email address:

    myemail://mailto?bob@gmail.com
    

    The only way it seems to get it to work in iOS9 is to remove any parameters.

    0 讨论(0)
  • 2020-11-22 07:22

    In Swift 4.2 and Xcode 10.1

    In info.plist need to add CFBundleURLSchemes and LSApplicationQueriesSchemes.

    --> Select info.plist in your project,

    --> right click,

    --> Select Open As Source Code

    See the below screen shot

    --> xml file will be opened

    --> copy - paste below code and replace with your ID's

    CFBundleURLSchemes and LSApplicationQueriesSchemes for gmail, fb, twitter and linked in.

    <key>CFBundleURLTypes</key>
        <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>li5****5</string>
                <string>com.googleusercontent.apps.8***************5f</string>
                <string>fb8***********3</string>
                <string>twitterkit-s***************w</string>
            </array>
        </dict>
    </array>
    <key>FacebookAppID</key>
    <string>8*********3</string>
    <key>FacebookDisplayName</key>
    <string>K************ app</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-share-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
    
        <string>twitter</string>
        <string>twitterauth</string>
    
        <string>linkedin</string>
        <string>linkedin-sdk2</string>
        <string>linkedin-sdk</string>
    
    </array>
    

    See below screen your final info.plist file is

    0 讨论(0)
  • 2020-11-22 07:26

    Facebook sharing from a share dialog fails even with @Matthieu answer (which is 100% correct for the rest of social URLs). I had to add a set of URL i reversed from Facebook SDK.

    <array>
            <string>fbapi</string>
            <string>fbauth2</string>
            <string>fbshareextension</string>
            <string>fb-messenger-api</string>
            <string>twitter</string>
            <string>whatsapp</string>
            <string>wechat</string>
            <string>line</string>
            <string>instagram</string>
            <string>kakaotalk</string>
            <string>mqq</string>
            <string>vk</string>
            <string>comgooglemaps</string>
            <string>fbapi20130214</string>                                                    
            <string>fbapi20130410</string>                                                     
            <string>fbapi20130702</string>                                                    
            <string>fbapi20131010</string>                                                    
            <string>fbapi20131219</string>                                                    
            <string>fbapi20140410</string>                                                     
            <string>fbapi20140116</string>                                                     
            <string>fbapi20150313</string>                                                     
            <string>fbapi20150629</string>
        </array>
    
    0 讨论(0)
提交回复
热议问题