Andree Wijaya Andree Wijaya - 6 months ago 45
iOS Question

Firebase code does not get executed on real iPhone device, only on emulators

I have the normal authentication code on my app, the code works fine on emulator. Once tested on device, it does not even start. Below is the snippets for Facebook login, same goes for Twitter or email/pass login.

if let fbLoginResult : FBSDKLoginManagerLoginResult = result {
if (fbLoginResult.grantedPermissions.contains("email")){
print("Facebook Token received!")
let token = FBSDKAccessToken.current().tokenString!
let credential = FIRFacebookAuthProvider.credential(withAccessToken: token)

print("Token : \(token)")

FIRAuth.auth()?.currentUser?.link(with: credential, completion: { (currentUser, linkingError) in
if linkingError != nil {
print("Linking error: \(linkingError?.localizedDescription)")
FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
if error == nil {
self.loginSucceeded(user: user!)
print("Error : \(error?.localizedDescription)")

self.loginSucceeded(user: currentUser!)


I have tried switching the Bitcode on Build settings to
. Still unable to work.

How to go about this? Much appreciated!


by "does not even start", which piece here doesn't start? Have you set up a debugger to determine which line of code is not getting executed? Just by looking at the snippet you've provided, my guess is:

FIRAuth.auth()?.currentUser?.link(with: credential, completion: { (currentUser, linkingError) in

This line will likely fail on a device that hasn't previously authenticated, since currentUser would be nil, I believe. I would make sure that this variable is non-nil as this is what is likely causing this issue.