Integration of Google Sign in with Swift
Posted By : Satish Phogat | 27-Jun-2017
In this blog , I am going to emplain the process of Google Sign - In using Swift 3
The easiest way of installation is using pod file .Open terminal and create pod file for particular project .Write
pod 'Google/SignIn'
Enter this line in pod file and exicute pod install command in terminal.
Get config. file by entering project name and bundle identifier and download GoogleService-info.plist file .Drag this downloaded file to project . It will create bridging header file .
Enter below line to bridging header file.
#import<Google/SignIn.h>
Go to project => info => Url Types and add two types and enter REVERSED_CLIENT_ID and BUNDLE_ID from downloaded info.plist.
Now add GIDSignInDelegate delegate to appdelegate class
Enter below code to didFinishLaunchingWithOptin method in app delegate
var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error : \(configureError)") GIDSignIn.sharedInstance().delegate = self
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { return GIDSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation]) }
func signIn(signIn: GIDSignIn!, didSignInForUser googleUser: GIDGoogleUser!, withError error: NSError!) {} func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, withError error: NSError!) {} func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {}
GIDSignIn.sharedInstance().uiDelegate = self
Due to this delegate view for google sign in will be visible.
We will have to add these three function in our view controller
public func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!){ self.present(viewController, animated: true, completion: nil) } public func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!){ } public func sign(inWillDispatch signIn: GIDSignIn!, error: Error!){ }
This is whole about Google Sign In.
Thanks.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Satish Phogat
Satish Phogat is IOS developer in Oodles Technologies. He is a good learner and Team Player.