30

While testing Google Sign-In 2.1.0 on the iOS 9 SDK, invoking GIDSignIn.sharedInstance().signInSilently() ends up crashing on an internal Google Sign-In SDK call to canOpenURL.

-canOpenURL: failed for URL: "com.googleusercontent.apps.1234567890-abcdefghijklmnopqrstuvwxyz://a" - error: "This app is not allowed to query for scheme com.googleusercontent.apps.1234567890-abcdefghijklmnopqrstuvwxyz"
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Your app must support the following URL schemes: com.example.foo, com.googleusercontent.apps.1234567890-abcdefghijklmnopqrstuvwxyz'

-canOpenURL: failed for URL: "com-google-gidconsent-google://" - error: "This app is not allowed to query for scheme com-google-gidconsent-google"
-canOpenURL: failed for URL: "com-google-gidconsent-youtube://" - error: "This app is not allowed to query for scheme com-google-gidconsent-youtube"
-canOpenURL: failed for URL: "com-google-gidconsent://" - error: "This app is not allowed to query for scheme com-google-gidconsent"
-canOpenURL: failed for URL: "com.google.gppconsent.2.4.1://" - error: "This app is not allowed to query for scheme com.google.gppconsent.2.4.1"
-canOpenURL: failed for URL: "com.google.gppconsent.2.4.0://" - error: "This app is not allowed to query for scheme com.google.gppconsent.2.4.0"
-canOpenURL: failed for URL: "googlechrome:" - error: "This app is not allowed to query for scheme googlechrome"
-canOpenURL: failed for URL: "googlechrome-x-callback:" - error: "This app is not allowed to query for scheme googlechrome-x-callback"
-canOpenURL: failed for URL: "googlechrome-x-callback:" - error: "This app is not allowed to query for scheme googlechrome-x-callback"
-canOpenURL: failed for URL: "googlechrome:" - error: "This app is not allowed to query for scheme googlechrome"

7 Answers7

46

iOS 9 has introduced new changes to canOpenURL requiring the application to whitelist all the schemes it needs to query.

This post on Quick Take on iOS 9 URL Scheme Changes explains why.

At a minimum you need to whitelist you own application’s identifier and your Google OAuth apps id in Info.plist under LSApplicationQueriesSchemes. You can also whitelist the other schemes Google Sign-In queries to silence the other warnings.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>com.example.foo</string>
    <string>com.googleusercontent.apps.1234567890-abcdefghijklmnopqrstuvwxyz</string>
    <string>com-google-gidconsent-google</string>
    <string>com-google-gidconsent-youtube</string>
    <string>com-google-gidconsent</string>
    <string>com.google.gppconsent.2.4.1</string>
    <string>com.google.gppconsent.2.4.0</string>
    <string>googlechrome</string>
    <string>googlechrome-x-callback</string>
</array>
  • Didn't work for me, I continuously get `NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)` – Awesome-o Sep 16 '15 at 00:50
  • whys it say this is not in the correct format for me? arnt i suppose to paste it in just before the last "" – 4GetFullOf Sep 20 '15 at 00:44
  • hello i can't run this it display error like as:- This app is not allowed to query for scheme Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Your app must support the following URL schemes: Please help me for that... – Kaushik Movaliya Oct 02 '15 at 08:56
  • Is that LSApplicationQueriesSchemes or NSApplicationQueriesSchemes – Saad Oct 06 '15 at 18:21
  • @Awesome-o The error you are receiving (KCFStreamErrorDomainSSL) is most likely an issue with NSAppTransportSecurity. Ultimately you should be whitelisting all of your external links in your app under that key but you can also simply use NSAllowsArbitraryLoads to blanket cover all external links. Take a look at this example: http://iosdevtips.co/post/121756573323/ios-9-xcode-7-http-connect-server-error – Alex Brashear Oct 13 '15 at 15:45
  • It's caused by Google Apps 3rd party 2-factor auth. I had to do as you said. The alternative would be to whitelist every individual 2-factor auth supported by Google. (Onelogin in the case I was testing.) What's odd is Onelogin actually meets all the requirements of ATS, so I think this may be a bug with iOS 9. I filed a bug report, they got back to me with what you suggested, the merry-go-round spins on... – Awesome-o Oct 13 '15 at 19:17
  • It's works for me, my schema fails was youtube, so add `youtube` and problem dissapear. – Adexe Rivera Oct 15 '15 at 09:16
13

Just follow the steps in: https://developers.google.com/identity/sign-in/ios/start-integrating#add_url_schemes_to_your_project (including adding the schemes) and it should be working fine.

And, as requested by comments below, I'll emphasise that the problem probably occurred by not adding the URL schemes as described in the link above.

Quoting from the link above:

Google Sign-in requires two custom URL Schemes to be added to your project.

To add the custom schemes:

  1. Open your project configuration: double-click the project name in the left tree view. Select your app from the TARGETS section, then select the Info tab, and expand the URL Types section.
  2. Click the + button, and add a URL scheme for your reversed client ID. To find this value, open the GoogleService-Info.plist configuration file, and look for the REVERSED_CLIENT_ID key. Copy the value of that key, and paste it into the URL Schemes box on the configuration page. Leave the other fields blank.
  3. Click the + button, and add a second URL scheme. This one is the same as your app's bundle ID. For example, if your bundle ID is com.example.app, type that value into the URL Schemes box. You can find your app's bundle ID in the General tab of the project configuration (Identity > Bundle Identifier).
emem
  • 5,588
  • 1
  • 24
  • 30
11

Updated for XCode 7.0 and Google plus Sdk 1.7.1

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>com-google-gidconsent-google</string>
        <string>com-google-gidconsent-youtube</string>
        <string>com-google-gidconsent</string>
        <string>com.google.gppconsent.2.4.1</string>
        <string>com.google.gppconsent.2.4.0</string>
        <string>googlechrome</string>
        <string>googlechrome-x-callback</string>
        <string>hasgplus4</string>
        <string>com.google.gppconsent.2.3.0</string>
        <string>com.google.gppconsent.2.2.0</string>
        <string>com.google.gppconsent</string>
    </array>

Reference Taken from this link

Sourabh Sharma
  • 8,222
  • 5
  • 68
  • 78
5

Josh's answer is correct for earlier versions of the Google Sign-in library. However, it looks like starting with version 2.2.0, this step is no longer necessary (hooray!).

So if you're still encountering this issue, my advice might be to update your Google Sign-In library.

Todd Kerpelman
  • 16,875
  • 4
  • 42
  • 40
  • 1
    This is working fine for iOS 9 in Xcode beta 7. Would it be safe to send application to appStore using this only, or should I add whitelist schemes as well to be safe (as the whole system is in beta stage). – sudhanshu-shishodia Sep 03 '15 at 05:35
5

After adding the GoogleService-Info.plist to my project, I added the following to the Info.plist file and the errors went away.

<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb1413410832299369</string>
            <string>com.my.app</string> <!-- My app bundle ID -->
            <string>com.googleusercontent.apps.1111111111-6jcxxxxxxxikgnso524xxxxxxxx5o9</string> <!-- Reverssed client ID -->
        </array>
    </dict>
</array>
Isuru
  • 30,617
  • 60
  • 187
  • 303
4

For me, putting the LSApplicationQueriesSchemes in the info.plist didn't work, but putting it under 'Project > Target > Info > URL Types' did the trick for me.

Chris
  • 7,830
  • 6
  • 38
  • 72
1

Add your com.googleusercontent.apps. into URL Types

Click into the Main Project -> Info -> URL Types