Integrating Google Sign-In into your iOS app

Google Sign-In manages the OAuth 2.0 flow and token lifecycle, simplifying your integration with Google APIs.

Before you begin

Download the dependencies and configure your Xcode project.

Enable sign-in

To enable sign in, you must configure the GIDSignIn shared instance. You can do this in many places in your app. Often the easiest place to configure this instance is in your app delegate's application:didFinishLaunchingWithOptions: method.

  1. In your app delegate's .h file, declare that this class implements the GIDSignInDelegate protocol.
    @import GoogleSignIn;
    @interface AppDelegate : UIResponder <UIApplicationDelegate, GIDSignInDelegate>
  2. In your app delegate's application:didFinishLaunchingWithOptions: method, configure the GIDSignIn shared instance and set the sign-in delegate.
    - (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      [GIDSignIn sharedInstance].clientID = @"YOUR_CLIENT_ID";
      [GIDSignIn sharedInstance].delegate = self;
      return YES;
  3. Implement the application:openURL:options: method of your app delegate. The method should call the handleURL method of the GIDSignIn instance, which will properly handle the URL that your application receives at the end of the authentication process.
    - (BOOL)application:(UIApplication *)app
                openURL:(NSURL *)url
                options:(NSDictionary<NSString *, id> *)options {
      return [[GIDSignIn sharedInstance] handleURL:url];

    For your app to run on iOS 8 and older, also implement the deprecated application:openURL:sourceApplication:annotation: method.

    - (BOOL)application:(UIApplication *)application
                openURL:(NSURL *)url
      sourceApplication:(NSString *)sourceApplication
             annotation:(id)annotation {
      return [[GIDSignIn sharedInstance] handleURL:url];
  4. In the app delegate, implement the GIDSignInDelegate protocol to handle the sign-in process by defining the following methods:
    - (void)signIn:(GIDSignIn *)signIn
    didSignInForUser:(GIDGoogleUser *)user
         withError:(NSError *)error {
      if (error != nil) {
        if (error.code == kGIDSignInErrorCodeHasNoAuthInKeychain) {
          NSLog(@"The user has not signed in before or they have since signed out.");
        } else {
          NSLog(@"%@", error.localizedDescription);
      // Perform any operations on signed in user here.
      NSString *userId = user.userID;                  // For client-side use only!
      NSString *idToken = user.authentication.idToken; // Safe to send to the server
      NSString *fullName =;
      NSString *givenName = user.profile.givenName;
      NSString *familyName = user.profile.familyName;
      NSString *email =;
      // ...
    - (void)signIn:(GIDSignIn *)signIn
    didDisconnectWithUser:(GIDGoogleUser *)user
         withError:(NSError *)error {
      // Perform any operations when the user disconnects from app here.
      // ...

Add the sign-in button

Next, you will add the Google Sign-In button so that the user can initiate the sign-in process. Make the following changes to the view controller that manages your app's sign-in screen:

  1. In the view controller, override the viewDidLoad method to set the presentingViewController of the GIDSignIn object, and (optionally) to restore the previous sign-in state when possible.
    - (void)viewDidLoad {
      [super viewDidLoad];
      [GIDSignIn sharedInstance].presentingViewController = self;
      // Automatically sign in the user.
      [[GIDSignIn sharedInstance] restorePreviousSignIn];
  2. Add a GIDSignInButton to your storyboard, XIB file, or instantiate it programmatically. To add the button to your storyboard or XIB file, add a View and set its custom class to GIDSignInButton.
  3. If you want to customize the button, do the following:
    1. In your view controller's .h file, declare the sign-in button as a property.
      @property(weak, nonatomic) IBOutlet GIDSignInButton *signInButton;
    2. Connect the button to the signInButton property you just declared.
    3. Customize the button by setting the properties of the GIDSignInButton object.

Next, you can implement and handle the sign-out button.

Sign out the user

You can use the signOut method of the GIDSignIn object to sign out your user on the current device, for example:

- (IBAction)didTapSignOut:(id)sender {
  [[GIDSignIn sharedInstance] signOut];