Google Sign-In crashes on iOS 9 attempting to call canOpenURL
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"
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>
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:
- 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.
- 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.
- 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).