Google Sign-In quick migration guide

Migrating from Google+ branding and scopes

To migrate your app from Google+ Sign-In to Google Sign-In, you’ll need to update your sign in button, the scopes you request from the user and how to retrieve profile information from Google. Follow our Google Sign-In for iOS documentation for full instructions.

When updating your sign in button, do not refer to Google+ or use the color red. See the updated branding guidelines.

Most G+ Sign In applications requested some combination of the scopes: plus.login, plus.me and plus.profile.emails.read. By setting shouldFetchBasicProfile to YES (the default) you will automatically request the profile and email scopes. These scopes will provide the user’s name, profile picture, and email.

Migrating from the Google+ Sign-In SDK

If you have an existing iOS application using the Google+ Sign-In SDK (GPPSignIn), this section shows you the bare minimum changes necessary to migrate your application to the Google Sign-In SDK (GIDSignIn).

1. Changes for the ViewController header file

  1. Add the Google Sign-In interface:

    #import <GoogleSignIn/GoogleSignIn.h>
    
  2. Make the class a delegate to receive Sign-In messages:

    @interface ViewController : UIViewController <GIDSignInDelegate, GIDSignInUIDelegate>
      // ... Typically, you'll add buttons here
    @end
    

2. Changes for the ViewController implementation file

  1. Import Google sources:

    #import <GoogleSignIn/GoogleSignIn.h>
    
  2. Initialize the GIDSignIn shared instance. Request the profile scope.

    @implementation ViewController
    - (void)viewDidLoad {
      [super viewDidLoad];
    
      GIDSignIn* signIn = [GIDSignIn sharedInstance];
      if (self.fetchEmailToggle.isEnabled) {
        signIn.shouldFetchBasicProfile = YES;
      } else {
        signIn.shouldFetchBasicProfile = NO;
      }
      signIn.clientID = kClientId;
      signIn.scopes = @[ @"profile" ];
      signIn.delegate = self;
      signIn.uiDelegate = self;
      self.statusField.text = @"Initialized auth2...";
    }
    
  3. Implement the delegate methods:

    - (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error {
        // Perform any operations on signed in user here.
      self.statusField.text = @"Signed in user";
    }
    - (void)signIn:(GIDSignIn *)signIn didDisconnectWithUser:(GIDGoogleUser *)user withError:(NSError *)error {
        // Perform any operations when the user disconnects from app here.
        self.statusField.text = @"Disconnected user";
    }
    
  4. Map buttons to Auth operations:

    - (IBAction)signInClicked:(id)sender {
      self.statusField.text = @"Clicked sign in!";
      [[GIDSignIn sharedInstance] signIn];
    }
    - (IBAction)signOutClicked:(id)sender {
      self.statusField.text = @"Clicked sign out!";
      [[GIDSignIn sharedInstance] signOut];
    }
    - (IBAction)disconnectClicked:(id)sender {
      self.statusField.text = @"Clicked disconnect!";
      [[GIDSignIn sharedInstance] disconnect];
    }
    - (IBAction)emailToggled:(id)sender {
      if (self.fetchEmailToggle.isEnabled) {
        [GIDSignIn sharedInstance].shouldFetchBasicProfile = YES;
      } else {
        [GIDSignIn sharedInstance].shouldFetchBasicProfile = NO;
      }
    }
    

3. Changes for the AppDelegate implementation file

  1. Import GoogleSignIn:

    #import <GoogleSignIn/GoogleSignIn.h>
    
  2. Handle the URL from OAuth responses:

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
          sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
      return [[GIDSignIn sharedInstance] handleURL:url sourceApplication:sourceApplication
          annotation:annotation];
    }
    

4. Add a URL type

In your project's Info tab, add a URL type. Specify a unique string in the Identifier field, and specify your client ID in reversed order in the URL Schemas field. For example, if your client ID for iOS is CLIENT_ID_CODE.apps.googleusercontent.com, then specify com.googleusercontent.apps.CLIENT_ID_CODE in the URL Schemas field.