在 react-native 中 ios 和 android 的 dev 和 prod 的不同 GoogleService-Info.plist 文件

Different GoogleService-Info.plist files for dev and prod for ios and android in react-native

我正在使用 react-native-google-signin 在应用程序中使用 google 登录。我在后端设置了一个 dev 和一个 prod google API 项目。

我想在我的 react-native 应用程序中为开发和生产使用单独的 GoogleService-Info.plist。

如何根据环境配置 GoogleService-Info.plist?

您需要根据您的环境进行配置。

NSString *firebasePlist = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"];

#if DEV
    firebasePlist = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info-DEV" ofType:@"plist"];
#endif

FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:firebasePlist];
[FIRApp configureWithOptions:options];

如果您已使用 https://console.developers.google.com 配置您的项目 无需在您的代码中配置任何内容。

默认情况下ANDROID可以设置3个环境

  1. 发展
  2. 发布
  3. Google 播放(制作)

ANDROID 为上述环境提供单独的 SHA-1 密钥。 使用这些 SHA-1 密钥,您可以创建 3 个 Oauth 项目。现在您有 3 个 Oauth google 项目,您可以使用项目的 3 个独立分支(开发、发布、生产)进行配置。

对于IOS

您可以创建任意数量的 Oauth google 项目。 只需在构建时根据环境在 ios 文件夹中保留 Oauth google 项目的 GoogleService-Info.plist。