My app is using Google SDK to collect users names when logged in. This works seamlessly. However, when I press the done button on the google login page I get the error. "Fatal error: unexpectedly found nil when unwrapping an optional value"
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
nameString = user.profile.name
defaults.set(nameString, forKey: "userName")
defaults.set(user.profile.email, forKey: "email")
defaults.set(user.profile.imageURL(withDimension: 50)!, forKey: "image")
print("email: \(user.profile.email!)")
print("name: \(user.profile.name!)")
print("lastname: \(user.profile.familyName!)")
print("lastname: \(user.profile.imageURL(withDimension: 50))")
self.dismiss(animated: true, completion: nil)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "UserLoggedIn"), object: nil)
So this is the function which I am using to receive names and saving them via userDeafaults.
The actual problem is the line "nameString = user.profile.name" Because when your press done on the login screen you are skipping to login. Which result in that it will not receive any data from user.profile.name.
How could I solve this problem? so if user.profile.name does not contain anything, it will not save the name to namestring.
Would really appreciate som help. Thank you :)