Let's point out some features of Google Sign in SDK:
1)Allow a user to log in through Google account.
2)Get user’s profile information.
The main objective of this blog post is to explain-how user can log into your application through Google account
You must need ClientID for Google Sign in
Make sure that you have a google account to get a ClientID.
Let me explain the procedure to get a ClientID from google account.
1)You need to sign intoGoogle Developers Console using your Google Account.
Create a Simple Swift App using Xcode,if you haven't created yet.
If you have already created an application, choose your application name.Add your App bundle identifier.
If it asks for your country/region.
You should put your country/region and click on Continue button.
Select Google service you want to use.
Now the Google Sign in service is enabled for your application.
Configure Your Xcode Project
Now, create a new Xcode project:
- However,to implement Google Sign-in service,you will need Google Sign-in SDK
- Download Google Sign-in SDK.
- Add GoogleService-Info.plist to the root of your Xcode project.
Check Copy items if needed checkbox and now you should click on Finish button,as shown below.
How to setup URL Types in Xcode?
In order to handle callback from Google,You need to setup URL Type.
- Find GoogleService-Info.plist in your finder and double click on it.
- You need to copy REVERSED_CLIENT_ID.
Go to Info and expand URL Types.
Just click on (+ ) button twice to create interface for two URL Types,as shown below.
Copy your project Bundle Identifier and paste on the second URL schemes.
Make sure that you have put the Google Sign-in SDK to your root project and copy items if needed should be checked.
Link Other dependent Frameworks to your projectGoogle Sign in SDK needs several other frameworks. Such as
How to add these frameworks?
Tap on your project in Project Navigator and go to Build Phases.
Click on + button and choose the required frameworks.
I strongly recommend to install cocoapods on your system.
Open your terminal and enter the command below.
sudo gem install cocoapods
How to Add Bridging Header ?GoogleSignIn.framework is written in Objective C.But,we need to use in Swift.So,bridging header can be the best way to use Objective C in Swift application.
How To Add A SWIFT Bridging Header in iOS
Put the line of code mentioned below in the Bridging Header file.
Now let's move into the coding section.
1)Open the AppDelegate.swift file and put the following code inside
You need to set your own application Client ID .
2)Add your AppDelegate.swift class to the subclass of GIDSignInDelegate as shown below.
5)Now it's time to add Google Sign-in Button so that user can do the login process.
Make your ViewController to the subclass of GIDSignInUIDelegate.
Hope this tutorial will be helpful adding Google SignIn SDK in iOS.
Please, share with me if you face any issues in a comment.
Download Sample Project here.