Flutter-Firebase phone Auth always returns Token mismatch on iOS

纵饮孤独 提交于 2020-01-05 08:32:20

问题


I'm trying to use phone Authentication and it's working as expected on Android, but on iOS I always get Token mismatch and don't receive a code.

other Firebase services like cloud firestore and email Auth are working fine on iOS.

I made sure of the following:

-APN key is added in Firebase

-Google Services file is updated

-Background Modes and Push Notification capabilities are on

the error message is from PhoneVerificationFailed

Future<void> _verifyPhoneNumber() async {

    setState(() {
      _message = '';
    });

    final PhoneVerificationCompleted verificationCompleted =
        (AuthCredential phoneAuthCredential) async {

      await _auth.signInWithCredential(phoneAuthCredential);

      setState(() {
        _message = 'Received phone auth credential: $phoneAuthCredential';

      });

    };

    final PhoneVerificationFailed verificationFailed =
        (AuthException authException) {
      setState(() {
        _message = '********************\n\n'
            'Phone number verification failed. Code: ${authException.code}.'
            '\n Message: ${authException.message}'
            '\n\n********************';
      });
    };

    final PhoneCodeSent codeSent =
        (String verificationId, [int forceResendingToken]) async {
      _verificationId = verificationId;

      setState(() {
        _message = 'waiting for code';
        //waitingCode = true;
      });
    };

    final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
        (String verificationId) {
      _verificationId = verificationId;
    };

    try {
      await _auth.verifyPhoneNumber(
          phoneNumber: number,
          timeout: const Duration(seconds: 30),
          verificationCompleted: verificationCompleted,
          verificationFailed: verificationFailed,
          codeSent: codeSent,
          codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
    } catch (e) {
      print('Error is $e');
    }
  }

and I'm getting these messages from log

Userinfo {
    "com.google.firebase.auth" =     {
        warning = "This fake notification should be forwarded to Firebase Auth.";
    };
}
UserDate : {
    "com.google.firebase.auth" =     {
        warning = "This fake notification should be forwarded to Firebase Auth.";
    };
}
UserDate Json : {
  "com.google.firebase.auth" : {
    "warning" : "This fake notification should be forwarded to Firebase Auth."
  }
}
flutter: 


TRUE
flutter: Call Back {
  "com.google.firebase.auth" : {
    "warning" : "This fake notification should be forwarded to Firebase Auth."
  }
}

回答1:


Changing the Firebase Auth version from 0.14.0 to

  firebase_auth:
    git:
      url: https://github.com/collinjackson/plugins.git
      ref: 441417c2fed0ff26bf84a49ab2c5ffd2aa5487de
      path: packages/firebase_auth

fixed my issue. see https://github.com/flutter/flutter/issues/35267 for more details



来源:https://stackoverflow.com/questions/57395948/flutter-firebase-phone-auth-always-returns-token-mismatch-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!