NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

Facebook login Access token is nil

Forums > Swift

I integrated the connection with facebook and firebase. when I try the button in the simulator, everything is fine. but when I test it on the iPhone, I get this error message Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

func loginButton(_ loginButton: FBLoginButton, didCompleteWith result: LoginManagerLoginResult?, error: Error?) { if let error = error { print(error.localizedDescription) return }

let current = AccessToken.current!.tokenString let credential = FacebookAuthProvider.credential(withAccessToken: current)


You trying to unwrap an optional you should unwrap it safely

if let current = AccessToken.current.tokenString {
  let credential = FacebookAuthProvider.credential(withAccessToken: current)


Thank, the connection with facebook work very well in the simulator but, he does not work when I test it with the iPhone.


Hacking with Swift is sponsored by Paw

SPONSORED Use Paw to build, test and describe web APIs. Paw has a lightning fast native macOS interface to compose requests, collaborate in real-time on API specs, and generate client code for your applications. You can import and export API definitions.

Discover Paw for Mac

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

Not logged in

Log in

Link copied to your pasteboard.