123

I am using Google Sign-In SDK 4.0.1. When I press googleSignInButton then app will be crash. And gave below error, how to fix this:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Your app is missing support for the following URL schemes: com.googleusercontent.apps.107731993306-6s44u18onibp6gi0ddj94si1aifshhg6'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000101ac0d4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010110121e objc_exception_throw + 48
    2   CoreFoundation                      0x0000000101b2a2b5 +[NSException raise:format:] + 197
    3   xxxxx                           0x000000010084b3cb -[GIDSignIn signInWithOptions:] + 246
    4   xxxxx                           0x000000010084efc2 -[GIDSignInButton pressed] + 242
    5   UIKit                               0x00000001028f78bc -[UIApplication sendAction:to:from:forEvent:] + 83
    6   UIKit                               0x0000000102a7dc38 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x0000000102a7df51 -[UIControl _sendActionsForEvents:withEvent:] + 444
    8   UIKit                               0x0000000102a7ce4d -[UIControl touchesEnded:withEvent:] + 668
    9   UIKit                               0x0000000102965545 -[UIWindow _sendTouchesForEvent:] + 2747
    10  UIKit                               0x0000000102966c33 -[UIWindow sendEvent:] + 4011
    11  UIKit                               0x00000001029139ab -[UIApplication sendEvent:] + 371
    12  UIKit                               0x000000010310072d __dispatchPreprocessedEventFromEventQueue + 3248
    13  UIKit                               0x00000001030f9463 __handleEventQueue + 4879
    14  CoreFoundation                      0x0000000101a65761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    15  CoreFoundation                      0x0000000101a4a98c __CFRunLoopDoSources0 + 556
    16  CoreFoundation                      0x0000000101a49e76 __CFRunLoopRun + 918
    17  CoreFoundation                      0x0000000101a49884 CFRunLoopRunSpecific + 420
    18  GraphicsServices                    0x00000001074cfa6f GSEventRunModal + 161
    19  UIKit                               0x00000001028f5c68 UIApplicationMain + 159
    20  xxxxxxxx                           0x00000001007c449f main + 111
    21  libdyld.dylib                       0x0000000104d5368d start + 1
    22  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException`

My AppDelegate.Swift is

class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
   if (error == nil) {

    let userId:NSString = user.userID as NSString;                  // For client-side use only!
    let idToken: NSString = user.authentication.idToken as NSString; // Safe to send to the server
    let fullName:NSString = user.profile.name as NSString;
    let givenName:NSString = user.profile.givenName as NSString;
    let familyName:NSString = user.profile.familyName as NSString;
    let email:NSString = user.profile.email as NSString;
    print(userId)
    print(userId,idToken,fullName,givenName,familyName,email)
    }

   else {
    print("\(error.localizedDescription)")
    }
}

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    let kclientID:NSString = "107731993306-xxxxxxxxxxxxxxxxx.apps.googleusercontent.com"

   GIDSignIn.sharedInstance().clientID = kclientID as String!

    GIDSignIn.sharedInstance().delegate = self
    return true
}


func application(application: UIApplication,
                 openURL url: NSURL, options: [String: AnyObject], annotation:Any, sourceApplication:String?) -> Bool {

    return GIDSignIn.sharedInstance().handle(url as URL!, sourceApplication:sourceApplication, annotation: annotation)
} 

Please give me the solution. Why it is crashed?

Vinodh
  • 5,262
  • 4
  • 38
  • 68
Vikas
  • 1,548
  • 2
  • 12
  • 25

14 Answers14

158

As the error clearly says, your app is missing support for the url schemes.

Add the following schemes to your info.plist

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>***Your bundle ID***</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>com.googleusercontent.apps.107731993306-6s44u18onibp6gi0ddj94si1aifshhg6</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>***Something here***</string>
        </array>
    </dict>
</array>

Check this url for your id => https://developers.google.com/identity/sign-in/ios/start-integrating

Your info.plist should look like ->

enter image description here

Kakshil Shah
  • 3,466
  • 1
  • 17
  • 31
129

You have to add a URL scheme to your project

  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 -com.googleusercontent.apps.107731993306-6s44u18onibp6gi0ddj94si1aifshh

https://developers.google.com/identity/sign-in/ios/start-integrating#add_a_url_scheme_for_google_sign-in_to_your_project

enter image description here

mokagio
  • 16,391
  • 3
  • 51
  • 58
Jack
  • 13,571
  • 6
  • 76
  • 98
  • 5
    This is IMO the easier (and typical) way to achieve the same thing as the accepted answer. – Eric May 23 '21 at 07:03
  • This must be the perfect answer! I just add a field under URL TYPES in info and it works! adding the same to the plist.info not working – Thiyagu Oct 03 '21 at 15:29
  • struggled also with this issue, SHA 1 key was already added but app crashed on every click on the "login with google" button of my flutter app Thanks, this answer here solved it. VS code > right click on iOS Folder > open in xcode > copy reversed_client_id from GoogleService-info.plist file you downloaded from firebase and stored to "iOS/Runner" before and add it as new URL Type (see screenshot) – golfo Mar 16 '23 at 07:31
33

I got that crash too. But accepted answer did not help me. I have fixed that crash in other way:

Double check that:

In AppDelegate straight DNS:

GIDSignIn.sharedInstance().clientID = "536164374389-ivga9a9at2g31nfmhpvdyhc98yf6afnr.apps.googleusercontent.com"

In Info.plist reverse DNS:

<string>com.googleusercontent.apps.536164374389-ivga9a9at2g31nfmhpvdyhc98yf6afnr</string>
Argus
  • 2,241
  • 1
  • 22
  • 27
26

Xcode gives you a string - Put it here as in the below image

enter image description here

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
coders
  • 2,287
  • 1
  • 12
  • 20
  • for those completely new to xcode, it would be helpful if you tell us where to find this screen – Flion Jun 30 '23 at 02:46
11

I ran into similar problem. Try this method if other methods didn't help you.

There is a chance you implemented Google and Facebook login together as they are often implemented together.

The latest Google Dev docs make you implement the URL scheme using Your Project Target > Info > URL Types. While Facebook docs will tell you to implement the url scheme in info.plist file. When you implement in .plist file the other URL Schemes will be replaced. So implement all URL Schemes in Project's Target section.

Your project target will look like this

Hope someone finds this helpful

rule_it_subir
  • 650
  • 10
  • 12
6

For those who came here from Flutter because of the crash of google_sign_in package on iOS devices - I've already covered this issue here

Long story short: try to explicitly set properties hostedDomain and clientId.

GoogleSignIn googleSignIn = GoogleSignIn( 
  scopes: ['email', 'profile'],
  hostedDomain: "", 
  clientId: "",);
Kirill Karmazin
  • 6,256
  • 2
  • 54
  • 42
3

you have to add reversed client id instead of normal one.

2

I've also waste over 4hours for similar logs (I'm developing ios app by flutter with VScode)

For me the main problem was GoogleService-Info.plist was not truly in the Runner directory.

I MUST had to add the GoogleService-Info.plist by XCODE, by right clicking Runner and add files button.

For overall, I learn that The flutter debugger(or vscode plugin?) does not give full information about the error.

Please look this for more information https://github.com/flutter/flutter/issues/22536

Check this image for what the 'Right clicking Runner and than add files'

hemistone
  • 71
  • 5
1

in GoogleSignIn SDK 5.0

add code

GIDSignIn.sharedInstance().delegate = self

GIDSignIn.sharedInstance().presentingViewController = self

instead of this code

GIDSignIn.sharedInstance().delegate = self

GIDSignIn.sharedInstance().uiDelegate = self

Rahul Patel
  • 179
  • 1
  • 5
1

in my case, using react native firebase, i had both the web and ios clientiD set, using only the iosClientId solved it for me GoogleSignin.configure({ webClientId: '' });

Dre Ole
  • 11
  • 2
1

Just invert the url to be like this: com.googleusercontent.apps.app_id

url types looks finally like this

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 23 '22 at 09:41
0

In my case I had two info.plist files one for debbug and one for production, make sure in both of them you've the same URL Schemes.

Adriatik Gashi
  • 332
  • 4
  • 10
0

If anybody tried all the options above and still get same error. Dont forget to add the Google-services.plist file in project.

vivek s
  • 91
  • 1
  • 3
-1

In my case, I forgot export GoogleService-info.plist from Firebase to my Xcode project.

Andrei R
  • 1,433
  • 2
  • 10
  • 16