guneshs

AppDelegate

May 15th, 2020
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.90 KB | None | 0 0
  1. import GoogleSignIn
  2. import Firebase
  3. import UIKit
  4.  
  5. @UIApplicationMain
  6. class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
  7.  
  8.     var window: UIWindow?
  9.     let defaults = UserDefaults.standard
  10.    
  11.     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  12.         // Override point for customization after application launch.
  13.         FirebaseApp.configure()
  14.          
  15.         GIDSignIn.sharedInstance()?.clientID = "333533065053-cf589bkjpujvjvd4t851pm2tthjula1e.apps.googleusercontent.com"
  16.         GIDSignIn.sharedInstance()?.delegate = self
  17.        
  18.        
  19.         return true
  20.     }
  21.  
  22.     func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
  23.        
  24.         if (error == nil) {
  25.            
  26.             // Perform any operations on signed in user here.
  27.              let userId = user.userID                  // For client-side use only!
  28.              let idToken = user.authentication.idToken // Safe to send to the server
  29.              let fullName = user.profile.name
  30.              let givenName = user.profile.givenName
  31.              let familyName = user.profile.familyName
  32.              let email = user.profile.email
  33.            
  34.            
  35.              print("\n\(String(describing: userId)) \n\(String(describing: idToken)) \n\(String(describing: fullName)) \n \(String(describing: givenName)) \n \(String(describing: familyName)) \n \(String(describing: email))");
  36.  
  37.   }
  38. self.defaults.synchronize()
  39.             let storyboard = UIStoryboard(name: "Main", bundle: nil)
  40.             let initialViewController = storyboard.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController
  41.              //withIdentifier: "HomeVC")
  42.             self.window?.rootViewController = initialViewController
  43.             self.window?.makeKeyAndVisible()
  44.            
  45.         } else {
  46.             print("\(error.localizedDescription)")
  47.         }
  48.     }
  49.  
  50.     func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
  51.         return GIDSignIn.sharedInstance().handle(url)
  52.     }
  53.    
  54.     // Added from firebase docs for working with ios 8 or older
  55.     func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
  56.         return GIDSignIn.sharedInstance().handle(url)
  57.     }
  58.    
  59.     func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  60.        
  61.         return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
  62.     }
  63.  
  64.     func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  65.        
  66.     }
  67. }
Add Comment
Please, Sign In to add comment