前提・実現したいこと
Flutter とFirebase Authを使ってログインできるようにしたいです。
APNのkeyを追加する前は普通にできていましたが、(push notification)をするためにAPNのKeyを追加したら以下のエラーメッセージが発生してしまいました。
APNを追加する前までは正常に動いていたのにとても謎です。助けてください。
発生している問題・エラーメッセージ
2020-03-15 13:14:28.499404+0900 Runner[9396:1934301] flutter: Token mismatch
自分のコード
Future<void> verifyPhone() async { print('veryfy phone func'); FirebaseAuth.instance.signOut(); print('veryfy phone func'); final PhoneCodeAutoRetrievalTimeout autoRetrieve = (String verId) { this.verificationId = verId; FirebaseAuth.instance.currentUser().then((user) { if (user != null) { print(user.phoneNumber); print(user.uid); } else {} }); }; final PhoneCodeSent smsCodeSent = (String verId, [int forceCodeResend]) async { this.verificationId = verId; await smsCodeDialog(context).then((value) { print('signed in'); }); }; final PhoneVerificationCompleted verificationSuccess = (AuthCredential user) { print('Phone Verification Completed'); }; final PhoneVerificationFailed verificationFailed = (AuthException exception) { print('${exception.message}'); }; await FirebaseAuth.instance.verifyPhoneNumber( phoneNumber: this.phoneNo, codeAutoRetrievalTimeout: autoRetrieve, codeSent: smsCodeSent, timeout: const Duration(seconds: 60), verificationCompleted: verificationSuccess, verificationFailed: verificationFailed, ); } Future<bool> smsCodeDialog(BuildContext context) { return showDialog( context: context, barrierDismissible: false, builder: (BuildContext context) { return new AlertDialog( title: Text('認証コードを送信しました。'), content: PinInputTextField( onChanged: (value) { this.smsCode = value; }, decoration: UnderlineDecoration(), ), contentPadding: EdgeInsets.all(10), actions: <Widget>[ FlatButton( child: Text('Done'), onPressed: () { FirebaseAuth.instance.currentUser().then((user) async { if (user != null) { print(user.phoneNumber); print(user.uid); final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); _firebaseMessaging.getToken().then((token) { print('token: $token'); Firestore.instance.collection('users').document(user.uid).collection('token').document('token') .setData({'pushToken': token}); }).catchError((err) { Fluttertoast.showToast(msg: err.message.toString()); }); Navigator.of(context).pop(); Navigator.of(context).pushReplacementNamed('/'); print("user exists!"); } else { print("good! first user"); signIn(); // print(user.uid); } }); }, ) ], ); }); } signIn() async { final AuthCredential credential = PhoneAuthProvider.getCredential( verificationId: verificationId, smsCode: smsCode); print(credential); AuthResult authResultJustForNewUser = await FirebaseAuth.instance.signInWithCredential(credential); final some = authResultJustForNewUser.additionalUserInfo.isNewUser; print(some); print("before add"); AuthResult authResult = await FirebaseAuth.instance .signInWithCredential(credential) .then((user) { }).catchError((e) { print('Auth Credential Error : $e'); }); final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); FirebaseAuth.instance.currentUser().then((user) { print('user.id is : ${user.uid}'); print(user.phoneNumber); print('printing uid and phonenumber'); _firebaseMessaging.getToken().then((token) { print('token: $token'); Firestore.instance.collection('users').document(user.uid).collection('token').document('token') .setData({'pushToken': token}); }).catchError((err) { Fluttertoast.showToast(msg: err.message.toString()); }); funcPost( username: "natsuki", password: user.phoneNumber, hash_id: user.uid); }); }
やったこと:
アプリを一度削除
flutter clean
build を削除
APN key からAPN certificateに変更
あなたの回答
tips
プレビュー