Skip to content

Instantly share code, notes, and snippets.

@ramamilaneh
Created January 20, 2017 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramamilaneh/0fbc742765457799ede4e3ac4bd00bd6 to your computer and use it in GitHub Desktop.
Save ramamilaneh/0fbc742765457799ede4e3ac4bd00bd6 to your computer and use it in GitHub Desktop.
func facebookSignInButtonTapped(with sender: LoginView) {
FBSDKLoginManager().logIn(withReadPermissions: ["email"], from: self, handler: { (result, error) in
guard result != nil, !(result?.isCancelled)!, error == nil else { return FBSDKLoginManager().logOut()}
if let accessToken = result?.token.tokenString {
let credential = FIRFacebookAuthProvider.credential(withAccessToken: accessToken)
FIRAuth.auth()?.signIn(with: credential) { (user, error) in
if let error = error {
print(error.localizedDescription)
let alert = UIAlertController(title: "error", message: "\(error.localizedDescription)", preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alert.addAction(okAction)
}else{
DispatchQueue.main.async {
NotificationCenter.default.post(name: .closeLoginVC, object: nil)
}
}
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment