Add Google Sign-In to Your iOS App
To use Google Sign-in in your app, add a GIDSignInButton
view to your app's sign-in screen.
Then, register your sign-in screen's view controller with the shared GIDSignIn
object:
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; [GIDSignIn sharedInstance].presentingViewController = self; }
Swift
func viewDidLoad() { super.viewDidLoad() GIDSignIn.sharedInstance().presentingViewController = self }
After a user clicks this button and signs in with their Google Account, the user's sign in status is passed to your app using the GIDSignInDelegate
protocol.

Conform to this protocol with your app delegate or another class, and implement the protocol's signIn:didSignInForUser:withError
method:
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)") } }
Then, in your app delegate, register your GIDSignInDelegate
and configure Google Sign-in with your client ID:
Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GIDSignIn sharedInstance].clientID = @"YOUR_CLIENT_ID"; [GIDSignIn sharedInstance].delegate = self; // If AppDelegate conforms to GIDSignInDelegate return YES; }
Swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Initialize sign-in GIDSignIn.sharedInstance().clientID = "YOUR_CLIENT_ID" GIDSignIn.sharedInstance().delegate = self // If AppDelegate conforms to GIDSignInDelegate return true }
Ready to integrate Google Sign-In into your app?