【问题标题】:Falling back to loading access token from NSUserDefaults because of simulator bug in Flutter由于 Flutter 中的模拟器错误,退回到从 NSUserDefaults 加载访问令牌
【发布时间】:2026-01-25 10:45:01
【问题描述】:

我已经厌倦了调试这个问题,但非常准确地说,我无法找到任何完美的解决方案。

以前我的应用程序运行流畅,没有任何麻烦,但现在我在登录我的帐户时收到此错误。

可能的问题:这是 Firebase 的问题,但模拟器无法将 accessToken 存储在模拟器中。

我已经关注了这些问题:

  1. Falling back to loading/storing access token from NSUserDefaults because of simulator bug
  2. Falling back to loading access token from NSUserDefaults because of simulator bug

现在我的应用程序运行良好,当我尝试登录时出现问题。我已经看到了解决方案,但根据上述研究对我来说没有任何效果。

到目前为止我所做的是:

  1. 重启应用
  2. 重新启动我的系统,并尝试运行应用程序
  3. 在我的pubspec.yaml 文件中更改了 FIREBASE_CORE 和 FIREBASE_AUTH 的版本
  4. 重新安装 XCode。同样的问题
  5. 这是我的 pubspec.yaml 文件中的颤振 firebase 包
  • firebase_core:^0.3.0
  • firebase_auth:^0.8.0

有了所有这些,一切都没有解决。错误似乎是一致的。

登录代码:

final AuthCredential credential = EmailAuthProvider.getCredential(email: this.email.text, password: this.password.text);
this._auth.signInWithCredential(credential).then((user) async {
}, onError: (e){
   Helpers.showError(context, (e as PlatformException).message);
});

错误:

1.首次运行应用时:

Launching lib/main.dart on iPhone 7 in debug mode...
Running Xcode build...                                                  
                                                   
 ├─Assembling Flutter resources...                           4.1s
 └─Compiling, linking and signing...                         7.0s
Xcode build done.                                           14.5s
Configuring the default Firebase app...
5.20.0 - [Firebase/Core][I-COR000004] App with name __FIRAPP_DEFAULT does not exist.
Configured the default Firebase app __FIRAPP_DEFAULT.
Falling back to loading access token from NSUserDefaults because of simulator bug
Falling back to storing access token in NSUserDefaults because of simulator bug
Falling back to loading access token from NSUserDefaults because of simulator bug
Falling back to storing access token in NSUserDefaults because of simulator bug
Falling back to loading access token from NSUserDefaults because of simulator bug
Falling back to storing access token in NSUserDefaults because of simulator bug
5.20.0 - [Firebase/Analytics][I-ACS023007] Analytics v.50801000 started
5.20.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled
flutter: in the main builder
flutter: in the init page state                                         
flutter: building the init page                                         
    "LocalUploadTask <A98F1971-4A48-4CDD-8658-567C6E24AE0E>.<1>"        
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask <A98F1971-4A48-4CDD-8658-567C6E24AE0E>.<1>, NSLocalizedDescription=cancelled} [-999]
<Google/Utilities/Network/ERROR> Encounter network error. Code, error: -999, Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://play.googleapis.com/log, NSErrorFailingURLKey=https://play.googleapis.com/log, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalUploadTask <A98F1971-4A48-4CDD-8658-567C6E24AE0E>.<1>"        
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask <A98F1971-4A48-4CDD-8658-567C6E24AE0E>.<1>, NSLocalizedDescription=cancelled}
5.20.0 - [GULNetwork][I-NET901017] <Google/Utilities/Network/ERROR> Encounter network error. Code, error: -999, Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://play.googleapis.com/log, NSErrorFailingURLKey=https://play.googleapis.com/log, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalUploadTask <A98F1971-4A48-4CDD-8658-567C6E24AE0E>.<1>"        
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask <A98F1971-4A48-4CDD-8658-567C6E24AE0E>.<1>, NSLocalizedDescription=cancelled}
        [C3.1.1 06A394ED-7FAF-45F0-ACCA-755A5E942EB5 ::1.56091<->::1.8080]
        Connected Path: satisfied (Path is satisfied), interface: lo0   
        Duration: 1.659s, DNS @0.005s took 0.013s, TCP @0.038s took 0.001s, TLS took 0.316s
        bytes in/out: 3907/808, packets in/out: 10/9, rtt: 0.000s, retransmitted packets: 0, out-of-order packets: 0
                                                                        
                                                                        
Your Facebook SDK is out of date. We recommend upgrading to the latest Version 4.37.0, to ensure your app's performance is not affected and to take advantage of our newest features!
                                                                        
Facebook SDK for iOS: https://developers.facebook.com/docs/ios/         
Facebook SDK for Android: https://developers.facebook.com/docs/android/ 
        [C2.1.1 D009F134-D0FD-41DF-BCB2-713CBD8875DF ::1.56090<->::1.8080]
        Connected Path: satisfied (Path is satisfied), interface: lo0   
        Duration: 1.729s, DNS @0.005s took 0.023s, TCP @0.037s took 0.014s, TLS took 0.295s
        bytes in/out: 4353/1054, packets in/out: 10/9, rtt: 0.000s, retransmitted packets: 0, out-of-order packets: 0
5.20.0 - [Firebase/Core][I-COR000020] Error posting to Clearcut: Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://play.googleapis.com/log, NSErrorFailingURLKey=https://play.googleapis.com/log, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalUploadTask <A98F1971-4A48-4CDD-8658-567C6E24AE0E>.<1>"        
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask <A98F1971-4A48-4CDD-8658-567C6E24AE0E>.<1>, NSLocalizedDescription=cancelled}, with Status Code: 0
flutter: building the init page                                         
flutter: building the init page                                         
        [C4.1.1 09BF4681-8112-4F65-84AA-824DC0C0F7A3 ::1.56101<->::1.8080]
        Connected Path: satisfied (Path is satisfied), interface: lo0   
        Duration: 0.622s, DNS @0.003s took 0.002s, TCP @0.020s took 0.001s, TLS took 0.148s
        bytes in/out: 3761/1543, packets in/out: 9/10, rtt: 0.000s, retransmitted packets: 0, out-of-order packets: 0
flutter: Calling GET API: /init                                         
Syncing files to device iPhone 7...                                     
flutter: {token: null, is_user_active: false, user: null}       
Syncing files to device iPhone 7...                                                          4,586ms (!)

2。当我尝试登录时:

Challenge SecTrustResultType 5 for www.googleapis.com, properties: (
        {
        type = error;
        value = "Root certificate is not trusted.";
    }
)
Cancelling authentication challenge for https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=XXXXXXXXXXXXXXXXXXXXXX
    "LocalDataTask <A48A2557-0E1B-4F61-8E54-B319538559DA>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <A48A2557-0E1B-4F61-8E54-B319538559DA>.<1>, NSLocalizedDescription=cancelled} [-999]

3. Firebase 抛出:

Network error (such as timeout, interrupted connection or unreachable host) has occurred

颤振医生:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.7.9-pre.9, on Mac OS X 10.14.5 18F132, locale en-US)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 10.0)
[✓] iOS tools - develop for iOS devices
[✓] Chrome - develop for the web
[!] Android Studio (version 3.4)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (3 available)

! Doctor found issues in 1 category.

接下来我可以尝试什么?

【问题讨论】:

    标签: ios firebase flutter runtime-error


    【解决方案1】:

    因为这是一个我们大多数人都不知道的错误,所以我决定自己写,因为我找到了解决方案。就这样吧。

    我已经尝试了很多东西,但我和我的团队一起想出了一些东西,那就是 Firebase 软件包版本有一些东西。因为我所做的是:

    1. 完全新建一个项目
    2. 将其连接到 Firebase
    3. 使用当前版本 firebase_auth 0.8.3
    4. 并运行项目,并确保您的登录有效
    5. 完成后,运行旧项目并查看它是否可以工作。

    可能是所有项目的包通常都存储在同一个文件中,所以cat .packages 会给你这个想法。

    谢谢,学习愉快!!!

    【讨论】: