簡體   English   中英

Flutter-Firebase 手機身份驗證始終在 iOS 上返回令牌不匹配

[英]Flutter-Firebase phone Auth always returns Token mismatch on iOS

我正在嘗試使用電話身份驗證,它在 Android 上按預期工作,但在 iOS 上我總是遇到令牌不匹配並且沒有收到代碼。

其他 Firebase 服務(如 cloud firestore 和電子郵件身份驗證)在 iOS 上運行良好。

我確定了以下幾點:

- 在 Firebase 中添加了 APN 密鑰

-Google 服務文件已更新

- 后台模式和推送通知功能開啟

錯誤消息來自 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');
    }
  }

我從日志中收到這些消息

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."
  }
}

我明白現在回答這個為時已晚。 但我最近也遇到了同樣的錯誤。 我在 iOS 上解決了這個問題。 您的整個配置必須有效。 您需要進行兩項設置。

  • 從 GoogleService-info.plist 中刪除任何方法 swizzling 變量,即從 plist 中刪除FirebaseAppDelegateProxyEnabled屬性

  • 在 AppDelegate.swift 中,覆蓋此方法並設置以下內容

    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { Messaging.messaging().apnsToken = deviceToken }

它在https://firebase.google.com/docs/cloud-messaging/ios/client#token-swizzle-disabled 中提到

我正在使用firebase_messaging: ^6.0.16並且上述設置有效

將 Firebase Auth 版本從 0.14.0 更改為

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

修復了我的問題。 有關更多詳細信息,請參閱https://github.com/flutter/flutter/issues/35267

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM