Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS 9 and iOS 10: -canOpenURL: failed for URL #22

Closed
ohh2ahh opened this issue Jul 24, 2015 · 23 comments
Closed

iOS 9 and iOS 10: -canOpenURL: failed for URL #22

ohh2ahh opened this issue Jul 24, 2015 · 23 comments

Comments

@ohh2ahh
Copy link
Owner

ohh2ahh commented Jul 24, 2015

AppAvailability Bug
appAvailability.check returns alway error callback.

Xcode error
-canOpenURL: failed for URL: "<scheme>://" - error: "This app is not allowed to query for scheme <scheme>"

Explanation
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. The article Quick Take on iOS 9 URL Scheme Changes expains the changes in detail.

Solution: Add URL Schemes to the Whitelist
Simply open your app's .plist (usually platforms/ios/<appname>/<appname>-Info.plist) with an editor and add the following code with your needed Schemes.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>twitter</string>
    <string>whatsapp</string>
</array>
@jason-engage
Copy link

thanks for the heads up

@ohh2ahh
Copy link
Owner Author

ohh2ahh commented Sep 6, 2015

Did you edit your Info.plist?

@jason-engage
Copy link

Yeah I added the code you provided to my plist (and read that link thx). Haven't tested it yet on ios9 tho.

@ohh2ahh
Copy link
Owner Author

ohh2ahh commented Sep 7, 2015

Ah, sorry. I tought that you had trouble implementing it :)

@J-Hong
Copy link

J-Hong commented Sep 17, 2015

Thank your help!

@seasun
Copy link

seasun commented Sep 18, 2015

how i do if urlschemes are from server .

@ohh2ahh
Copy link
Owner Author

ohh2ahh commented Sep 18, 2015

@seasun
I suppose you still have to include the schemes in your Info.plist when you're adding new schemes serve-side (at least if you've built your app with the iOS 9 SDK on Xcode 7).

As an alternative you could use the new Universal Links for iOS 9. Or you could build the app with the old SDK using Xcode 6 until Apple forces you to use Xcode 7. There's no need for scheme registration using Xcode 6.

@nilmeme
Copy link

nilmeme commented Sep 18, 2015

Thank your help! But I used paypal , which sschemes should I add to LSApplicationQueriesSchemes.

@ohh2ahh
Copy link
Owner Author

ohh2ahh commented Sep 18, 2015

@babydance
Paypal's URL scheme is paypal://, simply add this string without ://.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>paypal</string>
</array>

@nilmeme
Copy link

nilmeme commented Sep 18, 2015

@ohh2ahh
I had add paypal scheme just like you said ,but also doesn't work

@ohh2ahh
Copy link
Owner Author

ohh2ahh commented Sep 18, 2015

@babydance

  • What is not working?
  • What versions are you using (iOS, Xcode, AppAvailability)?
  • Is there an error in Xcode or in the console?

@seasun
Copy link

seasun commented Sep 18, 2015

@ohh2ahh
thanks ohh2ahh! Because of this , so I can not upgrade. Server's urlschemes are third-party support.

@nilmeme
Copy link

nilmeme commented Sep 18, 2015

@ohh2ahh
thanks ohh2ahh! I upgrade the apypal sdk,and then everything is ok!

@ohh2ahh
Copy link
Owner Author

ohh2ahh commented Sep 18, 2015

@babydance
I agree that Apple's privacy measures make an upgrade complicated. Hopefully third-party apps adopt the new universal links quickly.

@rjhilgefort
Copy link

For anyone working with an app where you can't know what might be linked to, I created a plugin to work around the issue. It's a simple plugin that injects a whitelist that covers commonly linked apps. Send me a PR if I forgot any.

https://github.com/rjhilgefort/cordova-plugin-queries-schemes

@electrobabe
Copy link

I had the same problem (ionic app running on iOS 9.2.1 built with XCode 7.2.1) and needed to add:

<allow-navigation href="twitter://*/*" />
<allow-navigation href="whatsapp://*/*" />

in config.xml additionally to

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>twitter</string>
  <string>whatsapp</string> 
</array>

in platforms/ios/<appname>/<appname>-Info.plist

@ohh2ahh ohh2ahh mentioned this issue Apr 3, 2016
@ramogundogdu
Copy link

where can i get the scheme of following ios app?: google hangouts, skype, ios mail app, my files, photo gallery and the scheme of on ios device installed apps?

@ohh2ahh
Copy link
Owner Author

ohh2ahh commented May 4, 2016

@ramogundogdu Unfortunately there isn't a complete register with url schemes. You can find known schemes of popular apps via a search engine.

@ohh2ahh ohh2ahh changed the title iOS 9: -canOpenURL: failed for URL iOS 9 and iOS 10: -canOpenURL: failed for URL Jun 16, 2016
@rolinger
Copy link

AppAvailability is working for me in Android - it opens right into the app. But on iOS its failing and thus gong to the company website. I have a hunch its the way I am calling the deeplink for iOS but can't find a better example to show me what I am doing wrong:

Example app:

if (dev==='iOS') { 
  scheme = "lyft://";
} else { 
  scheme = "me.lyft.android" ; //"lyft://" ;
}

var deepLink = "lyft:// ;
var url = "https://m.lyft.com/" ;

  appAvailability.check(
    scheme,
    function() {      // app is available
      window.open(deepLink,'_system','location=no') ;
    }, function () {  // app is not available, open website link
      window.open(url,'_system','location=no') ;
    }
  );

@ohh2ahh
Copy link
Owner Author

ohh2ahh commented Aug 22, 2016

@rolinger

Are you testing your app on an actual iOS device with Lyft installed? Which iOS version are you running? And did you add

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>lyft</string>
</array>

in platforms/ios/<appname>/<appname>-Info.plist?

@rolinger
Copy link

No....I did not have that in the -Info.plist file. My app is in beta test right now and all my iOS users are experiencing the same issue on their devices. All my testers are 9.2 or 9.3 (I think).

the LSApplicationQueriesSchemes already existed so all I need to do is just add the <string> correct? Does the string name have to match what is going to be defined as the scheme

i.e.: var scheme = 'fb://' = <string>fb</string> ....or does it actually need to say Facebook

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>instagram</string>
  <string>lyft</string>
  <string>facebook</string>
</array>
<key>LSRequiresIPhoneOS</key>

@ohh2ahh
Copy link
Owner Author

ohh2ahh commented Aug 22, 2016

@rolinger
Yes, since iOS 9.0 you have to add a string manually to the plist for each URL scheme you're using (see the explanation in my first comment). The string is the URL scheme without ://. This should work:

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>instagram</string>
  <string>lyft</string>
  <string>fb</string>
</array>

@rolinger
Copy link

Oh, I did read that previously but misunderstood it for something else. Getting it all added now, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants