Add Google Sign-In to Your iOS App

In your app delegate, configure the GGLContext object:

Objective-C
- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  NSError* configureError;
  [[GGLContext sharedInstance] configureWithError: &configureError];
  NSAssert(!configureError, @"Error configuring Google services: %@", configureError);

  [GIDSignIn sharedInstance].delegate = self;

  return YES;
}
Swift
func application(application: UIApplication,
  didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Initialize sign-in
    var configureError: NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)
    assert(configureError == nil, "Error configuring Google services: \(configureError)")

    GIDSignIn.sharedInstance().delegate = self

    return true
}

Then, add a GIDSignInButton view to your app.

Lastly, in the view controller, implement the signIn:didSignInForUser: method that will be called when the sign-in button is tapped:

Objective-C
- (void)signIn:(GIDSignIn *)signIn
    didSignInForUser:(GIDGoogleUser *)user
           withError:(NSError *)error {
  // Perform any operations on signed in user here.
  // ...
}
Swift
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
  withError error: NSError!) {
    if (error == nil) {
      // Perform any operations on signed in user here.
      // ...
    } else {
      println("\(error.localizedDescription)")
    }
}

Ready to integrate Google Sign-In into your app?

Get Started