In iOS we can login into the app through Social account, and then we don’t need to fill a long form to register into the app, let’s see below integrating GoogleSigin in iOS (Swift).
GoogleSignIn SDK installation
First, we need to install Google Sign-in pod.
1 |
pod 'GoogleSignIn' |
Here’s how your Podfile should look like:
Creating OAuth client ID for GoogleSignIn
After the SDK installation, you will need an OAuth client ID and an iOS URL scheme so that you can continue with the configuration in Xcode.
Now open Google APIs Console and create a project for your sample app. If you have already created a project, you can also select it from the project list.
After creating a project, we also need to configure the OAuth consent screen. Follow the steps as shown in the image below to choose your app user type and then create the OAuth consent screen.
In the OAuth consent screen information page, fill in the application name, and then click “save”. This application name will be the name being shown in the Google Sign-in form when a user tries to sign in using your app.
After finishing configuring the OAuth consent screen, it’s time to create the OAuth client ID. Please check the below image to navigate to the OAuth client ID creation page.
Once you reach the OAuth client ID creation page, go ahead and select “iOS” as application type, fill in the name and also your sample app bundle ID, and then click “create”.
Copy the OAuth client ID and iOS URL scheme you just created and save them, you will need both of them in just a bit.
GoogleSignIn SDK configuration in Xcode
Step1: Open project in xcode, select target and in Info section add iOS URL scheme in URL Types
Step2: Now, open AppDelegate class and import GoogleSignIn module.
1 |
import GoogleSignIn |
Step3: After that, add below code into application(_:didFinishLaunchingWithOptions:) method.
1 2 3 |
GIDSignIn.sharedInstance().clientID = "[OAuth_Client_ID]" GIDSignIn.sharedInstance().delegate = self GIDSignIn.sharedInstance()?.restorePreviousSignIn() |
Step4: Then just after application(_:didFinishLaunchingWithOptions:), add below method
1 2 3 4 5 6 7 8 9 |
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { var handle: Bool = true handle = GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation) return handle } |
Finally, the GoogleSignIn is implemented in our project, now we can run it and check GoogleSignIn.
As, we can see integrating GoogleSigin in iOS (Swift) is so easy, for more detailed information please check here.
Also check Google Signin implementation in objective-c here.