Over a million developers have joined DZone.

Learn How to Integrate Google Sign-in SDK Using Swift in iOS Application

DZone's Guide to

Learn How to Integrate Google Sign-in SDK Using Swift in iOS Application

This article shows you how to integrate Google Sign-in SDK in an iOS application using Swift.

· Mobile Zone ·
Free Resource

Due to the emergence of M-commerce mania, most of the operations are carried out through mobile applications. Mobiles are the medium that let user communicate with the world regardless of time and place. Nowadays, applications are leveraging users to chat, send images, video and voice recordings, Emails and many other kinds of stuff. So today, Indian App Developers will focus on how to integrate Google Sign-in SDK in an iOS application using Swift to make access easier.


Google Sign-in SDK impulsively handles out the sign-in process. Whenever you tap on the button it will ask the user to enter the signing credential for his/her Google account. Initially, you won't be able to see the sign in button in UI storyboard but, it will appear during run-time.


The main objective of this post is to explain how Google sign in option can be implemented in your iOS application.

Implementing Google Sign-in SDK

Step 1: Introduction

 Google SignIn SDK allows:

  1. Users to log in via Google account.
  2. Get user’s profile information details.

Here, I will explain how user can login to app through Google account but for that you need to have your account first.

To sign in to Google sign in you need to have clientID.

Step 2: Get Google Sign-in Client ID

Google sign in Client ID is an ID that allows us to make calls to Google API within our iOSbased application.

To get ClientID follow below steps:

  1. Sign into Google Developers Console with the help of your Google Account.
  2. If you have not created any app then create it. If created, then choose your app and add it to bundle identifier. Now choose your country and then click to continue Button to proceed ahead.
  3. Select the Google service that you want to make use of. Now, Select Google Sign-in & click -> ENABLE GOOGLE SIGN-IN to enable Google sign in service.
  4. Whenever you click on “Enable button”, it will sanction Google Sign in for your app.
  5. Whenever you enable Google Sign-in for your app, click -> Continue button that will generate configuration files for you.
  6. Now, you will be navigated to download the configuration file. Click -> Download GoogleService-info.plist button to download the configuration file. This file will be used for later purposes.

Step 3: Project Configuration

  1. Create a newer Xcode Project.
  2. Add GoogleService-Info.plist to the source of Xcode project.
  3. A new window will appear that helps you to choose the options to add files. Check “Copy items if needed” checkbox & click ->Finish button.
  4. Setup URL Types : Used to handle callbacks from Google.

3.1 Here Are the Steps

  1. Find GoogleService-Info.plist
  3. Just select your project from Navigator
  4. Select your app from “Project and Target List”
  5. Go -> Info and Expand -> URL Types
  6. Click -> '+' button to add URL Type
  7. Now Paste REVERSED_CLIENT_ID to URL Schemes
  8. Click '+' button to add another URL Type.
  9. Now paste your project “ Bundle Identifier”.

3.2 Add Other Frameworks

Google sign in also requires another framework such as:

  1. StoreKit.framework
  2. SystemConfiguration.framework
  3. AddressBook.framework

To add up this framework in your project select project from Project Navigator and click -> Build Phases. Expand the Link Binary With Libraries and click -> '+' button. Now you can choose and add needed frameworks.

3.2 Add Bridging Header

Use: Bridging Header helps us to make us of Objective-C code in our swift application.

Below is the code to bridge header file :

#import <GoogleSignIn/GoogleSignIn.h>

Step 4: Sign in Using Google

1. Open AppDelegate.swift and use below lines of codes in the method named application(_didFinishLaunchingWithOptions)

Image title

Here I would be making use of my API Key to integrate SDK in iOS app. You need to implement your key in the code.

2. Now Add your AppDelegate.swift class in the subclass of  GIDSignInDelegate:

class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate

3. Now open AppDelegate.swift and add below lines in the method named application(_openURL:,_options:)

Image title

This method is used to handle and maintain the URL that you receive at the end of the application process.

4) Add  GIDSignInDelegate() method inside AppDelegate.swift

Image title

This method is invoked when a user successfully signs into his account. You can retrieve user’s basic information through this method.

5. Add “Google Sign-in Button” to perform a sign-in process.

    a. Make your ViewController in subclass of  GIDSignInUIDelegate.        

class ViewController: UIViewController, GIDSignInUIDelegate

   b).Add below code to  viewDidLoad() method of your ViewController.

GIDSignIn.sharedInstance().uiDelegate = self

   c. Now Add UIView to the storyboard & Select the view and add GIDSignInButton as a custom class.

   d. Now declare an IBOutlet in your ViweController

@IBOutlet weak var signInButton: GIDSignInButton!

   e. Now connect IBOutlet with the UIView created in the storyboard

Image title

As per now, you are unable to look anything in the  UIView in storyboard though you have added GIDSignInButton  as the custom class. But once you run the app “Google Sign-in button” will be visible in the view during run time. Google Sign-in SDK handles and manages the sign-in process. Whenever you tap on the button it will ask for credentials of Google Account.

Step 5: Sign Out From Google Account

Below method needs to be called out to signout from Google Account:


Hope that you find the blog posted by me helpful when you begin your work with Google SignIn SDK in iOS. Let me know in comments if you have any concerns regarding Google Sign in iOS.

google ,ios applications development ,swift ,app development ,app developers ,ios ,ios app development ,ios development

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}