iOS 9 not opening Instagram app with URL SCHEME

IosSwiftXcodeCocoa TouchIos9

Ios Problem Overview


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't the URL open?

Ios Solutions


Solution 1 - Ios

iOS 9 has made a small change to the handling of URL scheme. You must whitelist the url's that your app will call out to using the LSApplicationQueriesSchemes key in your Info.plist.

Please see post here: http://awkwardhare.com/post/121196006730/quick-take-on-ios-9-url-scheme-changes

The main conclusion is that:

> If you call the “canOpenURL” method on a URL that is not in your whitelist, it will return “NO”, even if there is an app installed that has registered to handle this scheme. A “This app is not allowed to query for scheme xxx” syslog entry will appear. > > If you call the “openURL” method on a URL that is not in your whitelist, it will fail silently. A “This app is not allowed to query for scheme xxx” syslog entry will appear.

The author also speculates that this is a bug with the OS and Apple will fix this in a subsequent release.

Solution 2 - Ios

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

Solution 3 - Ios

This is a new security feature of iOS 9. Watch WWDC 2015 Session 703 for more information.

Any app built with SDK 9 needs to provide a LSApplicationQueriesSchemes entry in its plist file, declaring which schemes it attempts to query.

<key>LSApplicationQueriesSchemes</key>
<array>
 <string>urlscheme</string>
 <string>urlscheme2</string>
 <string>urlscheme3</string>
 <string>urlscheme4</string>
</array> 

Solution 4 - Ios

Assuming two apps TestA and TestB. TestB wants to query if TestA is installed. "TestA" defines the following URL scheme in its info.plist file:

<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleURLSchemes</key>
		<array>
			<string>testA</string>
		</array>
	</dict>
</array>

The second app "TestB" tries to find out if "TestA" is installed by calling:

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"TestA://"]];

But this will normally return NO in iOS9 because "TestA" needs to be added to the LSApplicationQueriesSchemes entry in TestB's info.plist file. This is done by adding the following code to TestB's info.plist file:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>TestA</string>
</array>

A working implementation can be found here: https://github.com/gatzsche/LSApplicationQueriesSchemes-Working-Example

Solution 5 - Ios

From, Session 703 WWDC 2015:

> You can continue to use URL schemes when you build your app for iOS 9 > and you want to call URL schemes, you will now need to declare them in > your apps Info.plist. There is a new key, LSApplicationQueriesSchemes, > and here you will need to add the list of schemes you want to are > canOpenURL on.

For instance, incase of FB

Solution 6 - Ios

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>

Solution 7 - Ios

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

enter image description here

--> 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

enter image description here

Solution 8 - Ios

It is important to note that there was a bug with jailbroken phones on 9.0.x which broke url schemes. If you're running a jailbroken device then make sure you update Patcyh in Cydia

Solution 9 - Ios

Well you can open an app by calling openURL: or openURL:options:completionHandler: (iOS 10 onwards) directly without making the conditional check canOpenURL:. Please read the discussion section in Apple doc for canOpenURL: method which says:

> the openURL: method is not constrained by the LSApplicationQueriesSchemes requirement.

Solution 10 - Ios

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://mail[email protected]

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

Solution 11 - Ios

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.

Solution 12 - Ios

For PayPal add below URL schemes :

enter image description here

Refer this link

Solution 13 - Ios

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>

Solution 14 - Ios

When I tried to call Facebook from my own app today, I found that there is no a LSApplicationQueriesSchemes key I can add to the Info.plist (Xcode Version 8.2.1 (8C1002)). I opened the Info.plist with Sublime Text and manually added it into the file, then it worked. Just to let you know that if you cannot find the key, simply add it yourself.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSk.AzadView Question on Stackoverflow
Solution 1 - IosthelawsView Answer on Stackoverflow
Solution 2 - IosMatthieu RouifView Answer on Stackoverflow
Solution 3 - IosLéo NatanView Answer on Stackoverflow
Solution 4 - IosAwsedView Answer on Stackoverflow
Solution 5 - IosKaeyView Answer on Stackoverflow
Solution 6 - IoselbuildView Answer on Stackoverflow
Solution 7 - IosNareshView Answer on Stackoverflow
Solution 8 - IosBuzzrickView Answer on Stackoverflow
Solution 9 - IosiphondroidView Answer on Stackoverflow
Solution 10 - IosDaveView Answer on Stackoverflow
Solution 11 - IosNishView Answer on Stackoverflow
Solution 12 - IosNaveen Kumar MView Answer on Stackoverflow
Solution 13 - IosVini AppView Answer on Stackoverflow
Solution 14 - Iosnumber_xView Answer on Stackoverflow