Firestore 电话验证导致 ios 崩溃 (Flutter)

Posted

技术标签:

【中文标题】Firestore 电话验证导致 ios 崩溃 (Flutter)【英文标题】:Firestore phone verification causes ios to crash (Flutter) 【发布时间】:2020-07-01 00:52:51 【问题描述】:

我正在尝试将电话验证添加到我的颤振应用中。它在 android 上似乎可以正常工作,但在 ios 手机验证上会导致应用程序立即崩溃。我在 pubspec.yaml 中使用以下内容:

firebase_auth: 0.15.4

dependency_overrides:
  firebase_core: 0.4.4

flutter doctor 的输出为:

[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.2 19C57, locale en-US)
    • Flutter version 1.12.13+hotfix.5 at /Users/gollyzoom/development/flutter
    • Framework revision 27321ebbad (3 months ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0


[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/gollyzoom/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3, Build version 11C29
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] IntelliJ IDEA Ultimate Edition (version 2019.1.4)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 38.1.3
    • Dart plugin version 191.8593

[✓] Connected device (2 available)
    • Android SDK built for x86 • emulator-5554                        • android-x86 • Android 9 (API 28) (emulator)
    • iPhone 11 Pro Max         • B3536B50-C435-4442-9CF4-69D470B979CA • ios         •
      com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

• No issues found!

我使用的实际代码是:

Future<void> verifyPhone() async 
    print("main");
    final PhoneCodeAutoRetrievalTimeout autoRetrieve = (String verId) 
      print("varification id");
      this.verificationId = verId;
    ;

    final PhoneCodeSent smsCodeSent = (String verId, [int forceCodeResend]) 
      print("send code dilog");
      this.verificationId = verId;
      smsCodeDialog(context).then((value) 
        print('Signed in');
      );
    ;

    final PhoneVerificationCompleted verifiedSuccess = (AuthCredential user)
      print('Phone Verification Completed');
    ;

    final PhoneVerificationFailed veriFailed = (AuthException exception) 
      print('$exception.message');
    ;

    await FirebaseAuth.instance.verifyPhoneNumber(

        phoneNumber: "+6505551234",
        codeAutoRetrievalTimeout: autoRetrieve,
        codeSent: smsCodeSent,
        timeout: const Duration(seconds: 5),
        verificationCompleted: verifiedSuccess,
        verificationFailed: veriFailed);
  

  Future<bool> smsCodeDialog(BuildContext context) 
    return showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) 
          return new AlertDialog(
            title: Text('Enter sms Code'),
            content: TextField(
              onChanged: (value) 
                this.smsCode = value;
              ,
            ),
            contentPadding: EdgeInsets.all(10.0),
            actions: <Widget>[
              new FlatButton(
                child: Text('Done'),
                onPressed: () 
                  FirebaseAuth.instance.currentUser().then((user) 
                    if (user != null) 
                      Navigator.of(context).pop();
                      Navigator.of(context).pushReplacementNamed('/homepage');
                     else 
                      Navigator.of(context).pop();
                      signIn();
                    
                  );
                ,
              )
            ],
          );
        );
  

  signIn() async 
    final AuthCredential credential = PhoneAuthProvider.getCredential(
      verificationId: verificationId,
      smsCode: smsCode,
    );
    final AuthResult authResult = await _auth.signInWithCredential(credential);
    final FirebaseUser user = authResult.user;
    print('User Id : ' + user.uid);
  

我从this 堆栈溢出帖子中获得了这段代码,但我不知道“在您的项目中添加反向客户端 ID”是什么意思。 (即什么是反向客户端 ID,我如何添加它),他们的代码并没有阻止应用程序为我崩溃。

【问题讨论】:

【参考方案1】:

我发现“反向客户端 ID”在 GoogleService-info.plist 中。这是您必须在 Xcode 中添加的内容。添加这个解决了崩溃。

【讨论】:

以上是关于Firestore 电话验证导致 ios 崩溃 (Flutter)的主要内容,如果未能解决你的问题,请参考以下文章

模型验证导致 iOS 应用崩溃

Firebase firestore 获取未经身份验证的用户文档

Flutter web firebase/firestore错误运行

在android中使用firebase电话身份验证时应用程序崩溃

Flutter cloud_firestore(0.9.0) 包在打开应用时崩溃

Cordova 插件电话号码在 iOS 最新版本上崩溃