i want to perform a segue from the App delegate in the google sign in methodiPhone app signing: A valid signing identity matching this profile could not be found in your keychainiOS - Calling App Delegate method from ViewControllerWrong type argument to unary minus 2How to perform Unwind segue programmatically?How do I get a reference to the app delegate in Swift?how do I perform segue after log in with google account?Create a segue to another view controller through search bar?Why can't segue from within GMSAutocompleteViewController with google autocomplete place pickerPerform Segue from App Delegate - SwiftI want to pause my GameScene, when the app moves in the Background (HomeButton, Call, etc.). How do I pause the GameScene from the AppDelegate File?

Name of transformation that maps numbers outside of interval onto endpoints?

Can a successful book series let the bad guy win?

Can a Pact of the Blade warlock turn a cursed magic weapon into your pact weapon to bypass the curse?

Checkmate in 1 on a Tangled Board

How can a valley surrounded by mountains be fertile and rainy?

What is an entropy graph

Most elegant way to write a one-shot 'if'

If I have the War Caster feat, can I use the Thorn Whip cantrip to stop an enemy caster from escaping using the Dimension Door spell?

Is it okay to submit a paper from a master's thesis without informing the advisor?

Simple logic puzzle

Can a stressful Wish's Strength reduction be cured early by a Greater Restoration spell?

What game is this character in the Pixels movie from?

When was this photo of Mission Dolores *actually* taken?

13th chords on guitar

Making a wall made from glass bricks

Converting Geographic Coordinates into Lambert2008 coordinates

Journal standards vs. personal standards

What is quadratization?

List Manipulation : a,b,c,d,e,f,g,h into a,b,c,d,e,f,g,h

Do home values typically rise and fall consistently across different price ranges?

/etc/hosts not working

Why can't you move another user's directory when you can move their file?

How do we separate rules of logic from non-logical constraints?

Sharing referee/AE report online to point out a grievous error in refereeing



i want to perform a segue from the App delegate in the google sign in method


iPhone app signing: A valid signing identity matching this profile could not be found in your keychainiOS - Calling App Delegate method from ViewControllerWrong type argument to unary minus 2How to perform Unwind segue programmatically?How do I get a reference to the app delegate in Swift?how do I perform segue after log in with google account?Create a segue to another view controller through search bar?Why can't segue from within GMSAutocompleteViewController with google autocomplete place pickerPerform Segue from App Delegate - SwiftI want to pause my GameScene, when the app moves in the Background (HomeButton, Call, etc.). How do I pause the GameScene from the AppDelegate File?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I have implemented Google Sign in with firebase and I have run into a problem.



I am trying to perform a segue from the App delegate if the if statement is true. The if statement works but whenever I run the perform segue method I either get a signal error or a Bad Access error with the embedded message:



viewController has no segue with identifier 'Test''. The extension is for taking a substring of the email and the var up top is irrelevant. I know this question has already been asked but it did not work for me and I think it may have something to do with Google sign In. My segues name is Test. The performSegue(withIdentifier: "Wegue", sender: self) is for the initial view controller once the google sign in is called.



let userDefault = UserDefaults()



func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?)
if let error = error
print(error.localizedDescription)
return


else
let userId = user.userID // For client-side use only!
let idToken = user.authentication.idToken // Safe to send to the server
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
let str = email



if(str == "wafster1337@gmail.com")
self.window?.rootViewController?.performSegue(withIdentifier: "Test", sender: self)



else
print("woe")





guard let authentication = user.authentication elsereturn
let crendential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
Auth.auth().signInAndRetrieveData(with: crendential) (result, error)in
if error == nil
self.userDefault.set(true, forKey: "usersignedIn")
self.userDefault.synchronize()
self.window?.rootViewController?.performSegue(withIdentifier: "Wegue", sender: self)

else

print(error?.localizedDescription ?? "me")













var window: UIWindow?




func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
// Override point for customization after application launch.

FirebaseApp.configure()
// Use Firebase library to configure APIs

GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
return true


func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
return GIDSignIn.sharedInstance().handle(url,
sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: [:])

func applicationWillResignActive(_ application: UIApplication)
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.


func applicationDidEnterBackground(_ application: UIApplication)
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


func applicationWillEnterForeground(_ application: UIApplication)
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.


func applicationDidBecomeActive(_ application: UIApplication)
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


func applicationWillTerminate(_ application: UIApplication)
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.


}
extension String

var length: Int
return count


subscript (i: Int) -> String
return self[i ..< i + 1]


func substring(fromIndex: Int) -> String
return self[min(fromIndex, length) ..< length]


func substring(toIndex: Int) -> String
return self[0 ..< max(0, toIndex)]


subscript (r: Range<Int>) -> String
let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
upper: min(length, max(0, r.upperBound))))
let start = index(startIndex, offsetBy: range.lowerBound)
let end = index(start, offsetBy: range.upperBound - range.lowerBound)
return String(self[start ..< end])












share|improve this question






























    2















    I have implemented Google Sign in with firebase and I have run into a problem.



    I am trying to perform a segue from the App delegate if the if statement is true. The if statement works but whenever I run the perform segue method I either get a signal error or a Bad Access error with the embedded message:



    viewController has no segue with identifier 'Test''. The extension is for taking a substring of the email and the var up top is irrelevant. I know this question has already been asked but it did not work for me and I think it may have something to do with Google sign In. My segues name is Test. The performSegue(withIdentifier: "Wegue", sender: self) is for the initial view controller once the google sign in is called.



    let userDefault = UserDefaults()



    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?)
    if let error = error
    print(error.localizedDescription)
    return


    else
    let userId = user.userID // For client-side use only!
    let idToken = user.authentication.idToken // Safe to send to the server
    let fullName = user.profile.name
    let givenName = user.profile.givenName
    let familyName = user.profile.familyName
    let email = user.profile.email
    let str = email



    if(str == "wafster1337@gmail.com")
    self.window?.rootViewController?.performSegue(withIdentifier: "Test", sender: self)



    else
    print("woe")





    guard let authentication = user.authentication elsereturn
    let crendential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
    Auth.auth().signInAndRetrieveData(with: crendential) (result, error)in
    if error == nil
    self.userDefault.set(true, forKey: "usersignedIn")
    self.userDefault.synchronize()
    self.window?.rootViewController?.performSegue(withIdentifier: "Wegue", sender: self)

    else

    print(error?.localizedDescription ?? "me")













    var window: UIWindow?




    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
    // Override point for customization after application launch.

    FirebaseApp.configure()
    // Use Firebase library to configure APIs

    GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
    GIDSignIn.sharedInstance().delegate = self
    return true


    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
    return GIDSignIn.sharedInstance().handle(url,
    sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
    annotation: [:])

    func applicationWillResignActive(_ application: UIApplication)
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.


    func applicationDidEnterBackground(_ application: UIApplication)
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


    func applicationWillEnterForeground(_ application: UIApplication)
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.


    func applicationDidBecomeActive(_ application: UIApplication)
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


    func applicationWillTerminate(_ application: UIApplication)
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.


    }
    extension String

    var length: Int
    return count


    subscript (i: Int) -> String
    return self[i ..< i + 1]


    func substring(fromIndex: Int) -> String
    return self[min(fromIndex, length) ..< length]


    func substring(toIndex: Int) -> String
    return self[0 ..< max(0, toIndex)]


    subscript (r: Range<Int>) -> String
    let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
    upper: min(length, max(0, r.upperBound))))
    let start = index(startIndex, offsetBy: range.lowerBound)
    let end = index(start, offsetBy: range.upperBound - range.lowerBound)
    return String(self[start ..< end])












    share|improve this question


























      2












      2








      2








      I have implemented Google Sign in with firebase and I have run into a problem.



      I am trying to perform a segue from the App delegate if the if statement is true. The if statement works but whenever I run the perform segue method I either get a signal error or a Bad Access error with the embedded message:



      viewController has no segue with identifier 'Test''. The extension is for taking a substring of the email and the var up top is irrelevant. I know this question has already been asked but it did not work for me and I think it may have something to do with Google sign In. My segues name is Test. The performSegue(withIdentifier: "Wegue", sender: self) is for the initial view controller once the google sign in is called.



      let userDefault = UserDefaults()



      func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?)
      if let error = error
      print(error.localizedDescription)
      return


      else
      let userId = user.userID // For client-side use only!
      let idToken = user.authentication.idToken // Safe to send to the server
      let fullName = user.profile.name
      let givenName = user.profile.givenName
      let familyName = user.profile.familyName
      let email = user.profile.email
      let str = email



      if(str == "wafster1337@gmail.com")
      self.window?.rootViewController?.performSegue(withIdentifier: "Test", sender: self)



      else
      print("woe")





      guard let authentication = user.authentication elsereturn
      let crendential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
      Auth.auth().signInAndRetrieveData(with: crendential) (result, error)in
      if error == nil
      self.userDefault.set(true, forKey: "usersignedIn")
      self.userDefault.synchronize()
      self.window?.rootViewController?.performSegue(withIdentifier: "Wegue", sender: self)

      else

      print(error?.localizedDescription ?? "me")













      var window: UIWindow?




      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
      // Override point for customization after application launch.

      FirebaseApp.configure()
      // Use Firebase library to configure APIs

      GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
      GIDSignIn.sharedInstance().delegate = self
      return true


      func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
      return GIDSignIn.sharedInstance().handle(url,
      sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
      annotation: [:])

      func applicationWillResignActive(_ application: UIApplication)
      // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
      // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.


      func applicationDidEnterBackground(_ application: UIApplication)
      // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
      // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


      func applicationWillEnterForeground(_ application: UIApplication)
      // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.


      func applicationDidBecomeActive(_ application: UIApplication)
      // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


      func applicationWillTerminate(_ application: UIApplication)
      // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.


      }
      extension String

      var length: Int
      return count


      subscript (i: Int) -> String
      return self[i ..< i + 1]


      func substring(fromIndex: Int) -> String
      return self[min(fromIndex, length) ..< length]


      func substring(toIndex: Int) -> String
      return self[0 ..< max(0, toIndex)]


      subscript (r: Range<Int>) -> String
      let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
      upper: min(length, max(0, r.upperBound))))
      let start = index(startIndex, offsetBy: range.lowerBound)
      let end = index(start, offsetBy: range.upperBound - range.lowerBound)
      return String(self[start ..< end])












      share|improve this question
















      I have implemented Google Sign in with firebase and I have run into a problem.



      I am trying to perform a segue from the App delegate if the if statement is true. The if statement works but whenever I run the perform segue method I either get a signal error or a Bad Access error with the embedded message:



      viewController has no segue with identifier 'Test''. The extension is for taking a substring of the email and the var up top is irrelevant. I know this question has already been asked but it did not work for me and I think it may have something to do with Google sign In. My segues name is Test. The performSegue(withIdentifier: "Wegue", sender: self) is for the initial view controller once the google sign in is called.



      let userDefault = UserDefaults()



      func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?)
      if let error = error
      print(error.localizedDescription)
      return


      else
      let userId = user.userID // For client-side use only!
      let idToken = user.authentication.idToken // Safe to send to the server
      let fullName = user.profile.name
      let givenName = user.profile.givenName
      let familyName = user.profile.familyName
      let email = user.profile.email
      let str = email



      if(str == "wafster1337@gmail.com")
      self.window?.rootViewController?.performSegue(withIdentifier: "Test", sender: self)



      else
      print("woe")





      guard let authentication = user.authentication elsereturn
      let crendential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
      Auth.auth().signInAndRetrieveData(with: crendential) (result, error)in
      if error == nil
      self.userDefault.set(true, forKey: "usersignedIn")
      self.userDefault.synchronize()
      self.window?.rootViewController?.performSegue(withIdentifier: "Wegue", sender: self)

      else

      print(error?.localizedDescription ?? "me")













      var window: UIWindow?




      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
      // Override point for customization after application launch.

      FirebaseApp.configure()
      // Use Firebase library to configure APIs

      GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
      GIDSignIn.sharedInstance().delegate = self
      return true


      func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
      return GIDSignIn.sharedInstance().handle(url,
      sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
      annotation: [:])

      func applicationWillResignActive(_ application: UIApplication)
      // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
      // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.


      func applicationDidEnterBackground(_ application: UIApplication)
      // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
      // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


      func applicationWillEnterForeground(_ application: UIApplication)
      // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.


      func applicationDidBecomeActive(_ application: UIApplication)
      // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


      func applicationWillTerminate(_ application: UIApplication)
      // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.


      }
      extension String

      var length: Int
      return count


      subscript (i: Int) -> String
      return self[i ..< i + 1]


      func substring(fromIndex: Int) -> String
      return self[min(fromIndex, length) ..< length]


      func substring(toIndex: Int) -> String
      return self[0 ..< max(0, toIndex)]


      subscript (r: Range<Int>) -> String
      let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
      upper: min(length, max(0, r.upperBound))))
      let start = index(startIndex, offsetBy: range.lowerBound)
      let end = index(start, offsetBy: range.upperBound - range.lowerBound)
      return String(self[start ..< end])









      ios swift xcode firebase






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 16:06









      Stijnk008

      1331 silver badge21 bronze badges




      1331 silver badge21 bronze badges










      asked Mar 25 at 14:40









      The Wafi CThe Wafi C

      134 bronze badges




      134 bronze badges






















          2 Answers
          2






          active

          oldest

          votes


















          1














          You first need to import google and firebase libraries.



          import FirebaseAuth
          import GoogleSignIn


          Sign in Function



          public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) 
          if (error == nil)
          guard let authentication = user.authentication else return
          let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
          Auth.auth().signInAndRetrieveData(with: credential) (authResult, error) in
          if let error != nil
          print("(error)")
          return
          else
          // User is succesfully logged in so settting userDefaults (I wouldn't recommend doing it this way to check if user logged in!)
          UserDefaults.standard.set(true, forKey: "usersignedIn")
          UserDefaults.standard.synchronize()

          // Now perform the segue to the viewController you want. Make sure you set the identifier the same as in the storyboard
          let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))!
          self.present(VC1, animated: true, completion: nil)


          else
          print("(String(describing: error))")




          To dismiss and show the controller



          func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) 
          self.dismiss(animated: true, completion: nil)


          func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!)
          self.present(viewController, animated: true, completion: nil)



          Call the login like this



          func googleButtonClicked() 
          GIDSignIn.sharedInstance().delegate = self
          GIDSignIn.sharedInstance().uiDelegate = self
          GIDSignIn.sharedInstance().signIn()






          share|improve this answer























          • So could I put my if statement right above: let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))! self.present(VC1, animated: true, completion: nil)

            – The Wafi C
            Mar 26 at 1:47











          • If this answer helped you could you mark it as completed by clicking the check? if you have any more questions please let me know

            – Stijnk008
            Mar 26 at 10:48











          • So I implemented your changes and its giving me an error of "use of unresolved identifier self" besides the sign methods and the googleButtonClicked() metho.Also the error " Value of type 'AppDelegate' has no member 'storyboard'" besides let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "Test"))!. I also want to be able to send my user to different view controller based on their email so I need a if statement.

            – The Wafi C
            Mar 27 at 13:20



















          0














          The solution is actually pretty simple and was staring me in the face the whole time



          I implemented multiple segues from my initial ViewController. I then took off the email's characters that came before the domain name. Then based on the domain name I performed a certain segue.



          @UIApplicationMain
          class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate



          let userDefault = UserDefaults()






          func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?)
          if let error = error
          print(error.localizedDescription)
          return


          else
          let userId = user.userID // For client-side use only!
          let idToken = user.authentication.idToken // Safe to send to the server
          let fullName = user.profile.name
          let givenName = user.profile.givenName
          let familyName = user.profile.familyName
          let email = user.profile.email
          let str = email
          let me = str?.count
          let int = (me!-9)
          let NewStr = str?.dropFirst(int)
          print(NewStr)




          guard let authentication = user.authentication elsereturn
          let crendential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
          Auth.auth().signInAndRetrieveData(with: crendential) (result, error)in
          if error == nil
          self.userDefault.set(true, forKey: "usersignedIn")
          self.userDefault.synchronize()
          if(NewStr == "gmail.com")

          self.window?.rootViewController?.performSegue(withIdentifier: "Megue", sender: self)

          else
          self.window?.rootViewController?.performSegue(withIdentifier: "Wegue", sender: self)
          print(error?.localizedDescription ?? "me")













          var window: UIWindow?




          func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
          // Override point for customization after application launch.

          FirebaseApp.configure()
          // Use Firebase library to configure APIs

          GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
          GIDSignIn.sharedInstance().delegate = self
          return true


          func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
          return GIDSignIn.sharedInstance().handle(url,
          sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
          annotation: [:])

          func applicationWillResignActive(_ application: UIApplication)
          // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
          // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.


          func applicationDidEnterBackground(_ application: UIApplication)
          // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
          // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


          func applicationWillEnterForeground(_ application: UIApplication)
          // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.


          func applicationDidBecomeActive(_ application: UIApplication)
          // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


          func applicationWillTerminate(_ application: UIApplication)
          // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.




          extension String



          var length: Int 
          return count


          subscript (i: Int) -> String
          return self[i ..< i + 1]


          func substring(fromIndex: Int) -> String
          return self[min(fromIndex, length) ..< length]


          func substring(toIndex: Int) -> String
          return self[0 ..< max(0, toIndex)]


          subscript (r: Range<Int>) -> String
          let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
          upper: min(length, max(0, r.upperBound))))
          let start = index(startIndex, offsetBy: range.lowerBound)
          let end = index(start, offsetBy: range.upperBound - range.lowerBound)
          return String(self[start ..< end])








          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55340326%2fi-want-to-perform-a-segue-from-the-app-delegate-in-the-google-sign-in-method%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You first need to import google and firebase libraries.



            import FirebaseAuth
            import GoogleSignIn


            Sign in Function



            public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) 
            if (error == nil)
            guard let authentication = user.authentication else return
            let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
            Auth.auth().signInAndRetrieveData(with: credential) (authResult, error) in
            if let error != nil
            print("(error)")
            return
            else
            // User is succesfully logged in so settting userDefaults (I wouldn't recommend doing it this way to check if user logged in!)
            UserDefaults.standard.set(true, forKey: "usersignedIn")
            UserDefaults.standard.synchronize()

            // Now perform the segue to the viewController you want. Make sure you set the identifier the same as in the storyboard
            let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))!
            self.present(VC1, animated: true, completion: nil)


            else
            print("(String(describing: error))")




            To dismiss and show the controller



            func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) 
            self.dismiss(animated: true, completion: nil)


            func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!)
            self.present(viewController, animated: true, completion: nil)



            Call the login like this



            func googleButtonClicked() 
            GIDSignIn.sharedInstance().delegate = self
            GIDSignIn.sharedInstance().uiDelegate = self
            GIDSignIn.sharedInstance().signIn()






            share|improve this answer























            • So could I put my if statement right above: let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))! self.present(VC1, animated: true, completion: nil)

              – The Wafi C
              Mar 26 at 1:47











            • If this answer helped you could you mark it as completed by clicking the check? if you have any more questions please let me know

              – Stijnk008
              Mar 26 at 10:48











            • So I implemented your changes and its giving me an error of "use of unresolved identifier self" besides the sign methods and the googleButtonClicked() metho.Also the error " Value of type 'AppDelegate' has no member 'storyboard'" besides let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "Test"))!. I also want to be able to send my user to different view controller based on their email so I need a if statement.

              – The Wafi C
              Mar 27 at 13:20
















            1














            You first need to import google and firebase libraries.



            import FirebaseAuth
            import GoogleSignIn


            Sign in Function



            public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) 
            if (error == nil)
            guard let authentication = user.authentication else return
            let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
            Auth.auth().signInAndRetrieveData(with: credential) (authResult, error) in
            if let error != nil
            print("(error)")
            return
            else
            // User is succesfully logged in so settting userDefaults (I wouldn't recommend doing it this way to check if user logged in!)
            UserDefaults.standard.set(true, forKey: "usersignedIn")
            UserDefaults.standard.synchronize()

            // Now perform the segue to the viewController you want. Make sure you set the identifier the same as in the storyboard
            let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))!
            self.present(VC1, animated: true, completion: nil)


            else
            print("(String(describing: error))")




            To dismiss and show the controller



            func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) 
            self.dismiss(animated: true, completion: nil)


            func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!)
            self.present(viewController, animated: true, completion: nil)



            Call the login like this



            func googleButtonClicked() 
            GIDSignIn.sharedInstance().delegate = self
            GIDSignIn.sharedInstance().uiDelegate = self
            GIDSignIn.sharedInstance().signIn()






            share|improve this answer























            • So could I put my if statement right above: let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))! self.present(VC1, animated: true, completion: nil)

              – The Wafi C
              Mar 26 at 1:47











            • If this answer helped you could you mark it as completed by clicking the check? if you have any more questions please let me know

              – Stijnk008
              Mar 26 at 10:48











            • So I implemented your changes and its giving me an error of "use of unresolved identifier self" besides the sign methods and the googleButtonClicked() metho.Also the error " Value of type 'AppDelegate' has no member 'storyboard'" besides let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "Test"))!. I also want to be able to send my user to different view controller based on their email so I need a if statement.

              – The Wafi C
              Mar 27 at 13:20














            1












            1








            1







            You first need to import google and firebase libraries.



            import FirebaseAuth
            import GoogleSignIn


            Sign in Function



            public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) 
            if (error == nil)
            guard let authentication = user.authentication else return
            let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
            Auth.auth().signInAndRetrieveData(with: credential) (authResult, error) in
            if let error != nil
            print("(error)")
            return
            else
            // User is succesfully logged in so settting userDefaults (I wouldn't recommend doing it this way to check if user logged in!)
            UserDefaults.standard.set(true, forKey: "usersignedIn")
            UserDefaults.standard.synchronize()

            // Now perform the segue to the viewController you want. Make sure you set the identifier the same as in the storyboard
            let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))!
            self.present(VC1, animated: true, completion: nil)


            else
            print("(String(describing: error))")




            To dismiss and show the controller



            func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) 
            self.dismiss(animated: true, completion: nil)


            func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!)
            self.present(viewController, animated: true, completion: nil)



            Call the login like this



            func googleButtonClicked() 
            GIDSignIn.sharedInstance().delegate = self
            GIDSignIn.sharedInstance().uiDelegate = self
            GIDSignIn.sharedInstance().signIn()






            share|improve this answer













            You first need to import google and firebase libraries.



            import FirebaseAuth
            import GoogleSignIn


            Sign in Function



            public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) 
            if (error == nil)
            guard let authentication = user.authentication else return
            let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
            Auth.auth().signInAndRetrieveData(with: credential) (authResult, error) in
            if let error != nil
            print("(error)")
            return
            else
            // User is succesfully logged in so settting userDefaults (I wouldn't recommend doing it this way to check if user logged in!)
            UserDefaults.standard.set(true, forKey: "usersignedIn")
            UserDefaults.standard.synchronize()

            // Now perform the segue to the viewController you want. Make sure you set the identifier the same as in the storyboard
            let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))!
            self.present(VC1, animated: true, completion: nil)


            else
            print("(String(describing: error))")




            To dismiss and show the controller



            func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) 
            self.dismiss(animated: true, completion: nil)


            func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!)
            self.present(viewController, animated: true, completion: nil)



            Call the login like this



            func googleButtonClicked() 
            GIDSignIn.sharedInstance().delegate = self
            GIDSignIn.sharedInstance().uiDelegate = self
            GIDSignIn.sharedInstance().signIn()







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 25 at 15:04









            Stijnk008Stijnk008

            1331 silver badge21 bronze badges




            1331 silver badge21 bronze badges












            • So could I put my if statement right above: let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))! self.present(VC1, animated: true, completion: nil)

              – The Wafi C
              Mar 26 at 1:47











            • If this answer helped you could you mark it as completed by clicking the check? if you have any more questions please let me know

              – Stijnk008
              Mar 26 at 10:48











            • So I implemented your changes and its giving me an error of "use of unresolved identifier self" besides the sign methods and the googleButtonClicked() metho.Also the error " Value of type 'AppDelegate' has no member 'storyboard'" besides let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "Test"))!. I also want to be able to send my user to different view controller based on their email so I need a if statement.

              – The Wafi C
              Mar 27 at 13:20


















            • So could I put my if statement right above: let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))! self.present(VC1, animated: true, completion: nil)

              – The Wafi C
              Mar 26 at 1:47











            • If this answer helped you could you mark it as completed by clicking the check? if you have any more questions please let me know

              – Stijnk008
              Mar 26 at 10:48











            • So I implemented your changes and its giving me an error of "use of unresolved identifier self" besides the sign methods and the googleButtonClicked() metho.Also the error " Value of type 'AppDelegate' has no member 'storyboard'" besides let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "Test"))!. I also want to be able to send my user to different view controller based on their email so I need a if statement.

              – The Wafi C
              Mar 27 at 13:20

















            So could I put my if statement right above: let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))! self.present(VC1, animated: true, completion: nil)

            – The Wafi C
            Mar 26 at 1:47





            So could I put my if statement right above: let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "yourIdentifier"))! self.present(VC1, animated: true, completion: nil)

            – The Wafi C
            Mar 26 at 1:47













            If this answer helped you could you mark it as completed by clicking the check? if you have any more questions please let me know

            – Stijnk008
            Mar 26 at 10:48





            If this answer helped you could you mark it as completed by clicking the check? if you have any more questions please let me know

            – Stijnk008
            Mar 26 at 10:48













            So I implemented your changes and its giving me an error of "use of unresolved identifier self" besides the sign methods and the googleButtonClicked() metho.Also the error " Value of type 'AppDelegate' has no member 'storyboard'" besides let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "Test"))!. I also want to be able to send my user to different view controller based on their email so I need a if statement.

            – The Wafi C
            Mar 27 at 13:20






            So I implemented your changes and its giving me an error of "use of unresolved identifier self" besides the sign methods and the googleButtonClicked() metho.Also the error " Value of type 'AppDelegate' has no member 'storyboard'" besides let VC1 = (self.storyboard?.instantiateViewController(withIdentifier: "Test"))!. I also want to be able to send my user to different view controller based on their email so I need a if statement.

            – The Wafi C
            Mar 27 at 13:20














            0














            The solution is actually pretty simple and was staring me in the face the whole time



            I implemented multiple segues from my initial ViewController. I then took off the email's characters that came before the domain name. Then based on the domain name I performed a certain segue.



            @UIApplicationMain
            class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate



            let userDefault = UserDefaults()






            func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?)
            if let error = error
            print(error.localizedDescription)
            return


            else
            let userId = user.userID // For client-side use only!
            let idToken = user.authentication.idToken // Safe to send to the server
            let fullName = user.profile.name
            let givenName = user.profile.givenName
            let familyName = user.profile.familyName
            let email = user.profile.email
            let str = email
            let me = str?.count
            let int = (me!-9)
            let NewStr = str?.dropFirst(int)
            print(NewStr)




            guard let authentication = user.authentication elsereturn
            let crendential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
            Auth.auth().signInAndRetrieveData(with: crendential) (result, error)in
            if error == nil
            self.userDefault.set(true, forKey: "usersignedIn")
            self.userDefault.synchronize()
            if(NewStr == "gmail.com")

            self.window?.rootViewController?.performSegue(withIdentifier: "Megue", sender: self)

            else
            self.window?.rootViewController?.performSegue(withIdentifier: "Wegue", sender: self)
            print(error?.localizedDescription ?? "me")













            var window: UIWindow?




            func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
            // Override point for customization after application launch.

            FirebaseApp.configure()
            // Use Firebase library to configure APIs

            GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
            GIDSignIn.sharedInstance().delegate = self
            return true


            func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
            return GIDSignIn.sharedInstance().handle(url,
            sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
            annotation: [:])

            func applicationWillResignActive(_ application: UIApplication)
            // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
            // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.


            func applicationDidEnterBackground(_ application: UIApplication)
            // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
            // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


            func applicationWillEnterForeground(_ application: UIApplication)
            // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.


            func applicationDidBecomeActive(_ application: UIApplication)
            // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


            func applicationWillTerminate(_ application: UIApplication)
            // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.




            extension String



            var length: Int 
            return count


            subscript (i: Int) -> String
            return self[i ..< i + 1]


            func substring(fromIndex: Int) -> String
            return self[min(fromIndex, length) ..< length]


            func substring(toIndex: Int) -> String
            return self[0 ..< max(0, toIndex)]


            subscript (r: Range<Int>) -> String
            let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
            upper: min(length, max(0, r.upperBound))))
            let start = index(startIndex, offsetBy: range.lowerBound)
            let end = index(start, offsetBy: range.upperBound - range.lowerBound)
            return String(self[start ..< end])








            share|improve this answer



























              0














              The solution is actually pretty simple and was staring me in the face the whole time



              I implemented multiple segues from my initial ViewController. I then took off the email's characters that came before the domain name. Then based on the domain name I performed a certain segue.



              @UIApplicationMain
              class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate



              let userDefault = UserDefaults()






              func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?)
              if let error = error
              print(error.localizedDescription)
              return


              else
              let userId = user.userID // For client-side use only!
              let idToken = user.authentication.idToken // Safe to send to the server
              let fullName = user.profile.name
              let givenName = user.profile.givenName
              let familyName = user.profile.familyName
              let email = user.profile.email
              let str = email
              let me = str?.count
              let int = (me!-9)
              let NewStr = str?.dropFirst(int)
              print(NewStr)




              guard let authentication = user.authentication elsereturn
              let crendential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
              Auth.auth().signInAndRetrieveData(with: crendential) (result, error)in
              if error == nil
              self.userDefault.set(true, forKey: "usersignedIn")
              self.userDefault.synchronize()
              if(NewStr == "gmail.com")

              self.window?.rootViewController?.performSegue(withIdentifier: "Megue", sender: self)

              else
              self.window?.rootViewController?.performSegue(withIdentifier: "Wegue", sender: self)
              print(error?.localizedDescription ?? "me")













              var window: UIWindow?




              func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
              // Override point for customization after application launch.

              FirebaseApp.configure()
              // Use Firebase library to configure APIs

              GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
              GIDSignIn.sharedInstance().delegate = self
              return true


              func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
              return GIDSignIn.sharedInstance().handle(url,
              sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
              annotation: [:])

              func applicationWillResignActive(_ application: UIApplication)
              // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
              // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.


              func applicationDidEnterBackground(_ application: UIApplication)
              // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
              // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


              func applicationWillEnterForeground(_ application: UIApplication)
              // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.


              func applicationDidBecomeActive(_ application: UIApplication)
              // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


              func applicationWillTerminate(_ application: UIApplication)
              // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.




              extension String



              var length: Int 
              return count


              subscript (i: Int) -> String
              return self[i ..< i + 1]


              func substring(fromIndex: Int) -> String
              return self[min(fromIndex, length) ..< length]


              func substring(toIndex: Int) -> String
              return self[0 ..< max(0, toIndex)]


              subscript (r: Range<Int>) -> String
              let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
              upper: min(length, max(0, r.upperBound))))
              let start = index(startIndex, offsetBy: range.lowerBound)
              let end = index(start, offsetBy: range.upperBound - range.lowerBound)
              return String(self[start ..< end])








              share|improve this answer

























                0












                0








                0







                The solution is actually pretty simple and was staring me in the face the whole time



                I implemented multiple segues from my initial ViewController. I then took off the email's characters that came before the domain name. Then based on the domain name I performed a certain segue.



                @UIApplicationMain
                class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate



                let userDefault = UserDefaults()






                func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?)
                if let error = error
                print(error.localizedDescription)
                return


                else
                let userId = user.userID // For client-side use only!
                let idToken = user.authentication.idToken // Safe to send to the server
                let fullName = user.profile.name
                let givenName = user.profile.givenName
                let familyName = user.profile.familyName
                let email = user.profile.email
                let str = email
                let me = str?.count
                let int = (me!-9)
                let NewStr = str?.dropFirst(int)
                print(NewStr)




                guard let authentication = user.authentication elsereturn
                let crendential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
                Auth.auth().signInAndRetrieveData(with: crendential) (result, error)in
                if error == nil
                self.userDefault.set(true, forKey: "usersignedIn")
                self.userDefault.synchronize()
                if(NewStr == "gmail.com")

                self.window?.rootViewController?.performSegue(withIdentifier: "Megue", sender: self)

                else
                self.window?.rootViewController?.performSegue(withIdentifier: "Wegue", sender: self)
                print(error?.localizedDescription ?? "me")













                var window: UIWindow?




                func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
                // Override point for customization after application launch.

                FirebaseApp.configure()
                // Use Firebase library to configure APIs

                GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
                GIDSignIn.sharedInstance().delegate = self
                return true


                func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
                return GIDSignIn.sharedInstance().handle(url,
                sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
                annotation: [:])

                func applicationWillResignActive(_ application: UIApplication)
                // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
                // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.


                func applicationDidEnterBackground(_ application: UIApplication)
                // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
                // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


                func applicationWillEnterForeground(_ application: UIApplication)
                // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.


                func applicationDidBecomeActive(_ application: UIApplication)
                // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


                func applicationWillTerminate(_ application: UIApplication)
                // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.




                extension String



                var length: Int 
                return count


                subscript (i: Int) -> String
                return self[i ..< i + 1]


                func substring(fromIndex: Int) -> String
                return self[min(fromIndex, length) ..< length]


                func substring(toIndex: Int) -> String
                return self[0 ..< max(0, toIndex)]


                subscript (r: Range<Int>) -> String
                let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
                upper: min(length, max(0, r.upperBound))))
                let start = index(startIndex, offsetBy: range.lowerBound)
                let end = index(start, offsetBy: range.upperBound - range.lowerBound)
                return String(self[start ..< end])








                share|improve this answer













                The solution is actually pretty simple and was staring me in the face the whole time



                I implemented multiple segues from my initial ViewController. I then took off the email's characters that came before the domain name. Then based on the domain name I performed a certain segue.



                @UIApplicationMain
                class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate



                let userDefault = UserDefaults()






                func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?)
                if let error = error
                print(error.localizedDescription)
                return


                else
                let userId = user.userID // For client-side use only!
                let idToken = user.authentication.idToken // Safe to send to the server
                let fullName = user.profile.name
                let givenName = user.profile.givenName
                let familyName = user.profile.familyName
                let email = user.profile.email
                let str = email
                let me = str?.count
                let int = (me!-9)
                let NewStr = str?.dropFirst(int)
                print(NewStr)




                guard let authentication = user.authentication elsereturn
                let crendential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
                Auth.auth().signInAndRetrieveData(with: crendential) (result, error)in
                if error == nil
                self.userDefault.set(true, forKey: "usersignedIn")
                self.userDefault.synchronize()
                if(NewStr == "gmail.com")

                self.window?.rootViewController?.performSegue(withIdentifier: "Megue", sender: self)

                else
                self.window?.rootViewController?.performSegue(withIdentifier: "Wegue", sender: self)
                print(error?.localizedDescription ?? "me")













                var window: UIWindow?




                func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
                // Override point for customization after application launch.

                FirebaseApp.configure()
                // Use Firebase library to configure APIs

                GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
                GIDSignIn.sharedInstance().delegate = self
                return true


                func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
                return GIDSignIn.sharedInstance().handle(url,
                sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
                annotation: [:])

                func applicationWillResignActive(_ application: UIApplication)
                // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
                // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.


                func applicationDidEnterBackground(_ application: UIApplication)
                // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
                // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


                func applicationWillEnterForeground(_ application: UIApplication)
                // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.


                func applicationDidBecomeActive(_ application: UIApplication)
                // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


                func applicationWillTerminate(_ application: UIApplication)
                // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.




                extension String



                var length: Int 
                return count


                subscript (i: Int) -> String
                return self[i ..< i + 1]


                func substring(fromIndex: Int) -> String
                return self[min(fromIndex, length) ..< length]


                func substring(toIndex: Int) -> String
                return self[0 ..< max(0, toIndex)]


                subscript (r: Range<Int>) -> String
                let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
                upper: min(length, max(0, r.upperBound))))
                let start = index(startIndex, offsetBy: range.lowerBound)
                let end = index(start, offsetBy: range.upperBound - range.lowerBound)
                return String(self[start ..< end])









                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 29 at 13:29









                The Wafi CThe Wafi C

                134 bronze badges




                134 bronze badges



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55340326%2fi-want-to-perform-a-segue-from-the-app-delegate-in-the-google-sign-in-method%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해