首页 > 解决方案 > 在 Firebase 中,使用 FlutterFire,如何在 iOS 上初始化辅助应用程序?InitializeApp 与选项给出 GOOGLE_APP_ID 错误

问题描述

在 Flutter 应用程序中,使用 FlutterFire 连接到 Firebase,使用以下代码连接到辅助存储:

  FirebaseApp hostApp;
  try {
    hostApp = Firebase.app("HostApp");
  } catch (e) {
    hostApp = await Firebase.initializeApp(
        name: 'HostApp',
        options: FirebaseOptions(
            appId: ConfigService.hostAppId,
            apiKey: ConfigService.hostApiKey,
            authDomain: ConfigService.hostAuthDomain,
            storageBucket: ConfigService.hostStorageBucket,
            projectId: ConfigService.hostProjectId,
            messagingSenderId: ConfigService.hostMessagingSenderId));
  }
  _storage = firebase_storage.FirebaseStorage.instanceFor(app: hostApp);

在 Android 上有效,但在 iOS 上,initializeApp 出现此错误:

    7.3.0 - [Firebase/Core][I-COR000009] The GOOGLE_APP_ID either in the plist file 'GoogleService-Info.plist' or the one set in the customized options is invalid.
If you are using the plist file, use the iOS version of bundle identifier to download the file, and do not manually edit the GOOGLE_APP_ID. You may change your app's bundle identifier to 'app.myapp'.
Or you can download a new configuration file that matches your bundle identifier from https://console.firebase.google.com/ and replace the current one.
    *** Terminating app due to uncaught exception 'com.firebase.core', reason: 'Configuration fails. It may be caused by an invalid GOOGLE_APP_ID in GoogleService-Info.plist or set in the customized options.'
        *** First throw call stack:
        (
            0   CoreFoundation                      0x000000010c627b0b __exceptionPreprocess + 171
            1   libobjc.A.dylib                     0x000000010c08c141 objc_exception_throw + 48
            2   CoreFoundation                      0x000000010c690625 +[NSException raise:format:] + 197
            3   Runner                              0x00000001088fb926 +[FIRApp addAppToAppDictionary:] + 278
            4   Runner                              0x00000001088fab12 +[FIRApp configureWithName:options:] + 1266

我添加了 iosClientId 和 iosBundleId 选项,但给出了同样的错误。

默认应用程序已经初始化:

WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

捆绑包标识符是正确的。

如何在 iOS 上初始化辅助应用程序?

标签: iosfirebaseflutter

解决方案


我使用的是网络 appId(例如 1:12345678: web :123abcd456efg78)。我已经更改了 iOS appId 的 appId 并且它可以工作。

在 Android 上有效,但在 iOS 上给出此错误。


推荐阅读