Earlier I have published a video tutorial on Sign-in with Facebook account and Sign-in with Twitter account. In this video tutorial I am going to share with you how to implement Sign-in with Google account feature for your mobile app.
I hope you find these two videos valuable.
If you are interested in learning more about User Sing-up for your mobile app process with either Parse or PHP & MySQL, there are more videos I have which I have organized into two videos courses:
1. Sign-in & Sign-up with Swift & Parse video course: https://goo.gl/a4jWz1
2. Sign-in & Sign-up with Swift, PHP and MySQL: https://goo.gl/CG4xKY
and here is now Sign-in with Google Account:
Link to Google Guides on Sign-in with Google Account.
Video 1. Configure Xcode project.
Video 2. Implement Sign-in and Sign out button
AppDelegate source code:
import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. // Initialize sign-in var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \(configureError)") GIDSignIn.sharedInstance().delegate = self return true } func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation) } func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) { if (error == nil) { // Perform any operations on signed in user here. //let userId = user.userID // For client-side use only! //let idToken = user.authentication.idToken // Safe to send to the server let name = user.profile.name //let email = user.profile.email print("User name \(name)") // [START_EXCLUDE] NSNotificationCenter.defaultCenter().postNotificationName( "ToggleAuthUINotification", object: nil, userInfo: ["statusText": "Signed in user:\n\(name)"]) // [END_EXCLUDE] let myStoryBoard:UIStoryboard = UIStoryboard(name:"Main", bundle:nil) let protectedPage = myStoryBoard.instantiateViewControllerWithIdentifier("ProtectedPageViewController") as! ProtectedPageViewController let protectedPageNav = UINavigationController(rootViewController: protectedPage) self.window?.rootViewController = protectedPageNav } else { print("\(error.localizedDescription)") // [START_EXCLUDE silent] NSNotificationCenter.defaultCenter().postNotificationName( "ToggleAuthUINotification", object: nil, userInfo: nil) // [END_EXCLUDE] } } func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, withError error: NSError!) { // Perform any operations when the user disconnects from app here. // [START_EXCLUDE] NSNotificationCenter.defaultCenter().postNotificationName( "ToggleAuthUINotification", object: nil, userInfo: ["statusText": "User has disconnected."]) // [END_EXCLUDE] } func applicationWillResignActive(application: UIApplication) { } func applicationDidEnterBackground(application: UIApplication) { } func applicationWillEnterForeground(application: UIApplication) { } func applicationDidBecomeActive(application: UIApplication) { } func applicationWillTerminate(application: UIApplication) { } }
Download source code to this project from GitHub.
Happy learning!
Sergey