react-native中针对iOS和android的dev和prod的不同GoogleService-Info.plist文件

时间:2020-09-17 11:25:30

标签: ios react-native react-native-android react-native-ios google-signin

我正在使用react-native-google-signin的应用程序中使用google登录。我在后端设置了一个开发人员和产品Google API项目。

我想在我的本机应用程序中将单独的GoogleService-Info.plist用于开发和生产。

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

2 个答案:

答案 0 :(得分:0)

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

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];

答案 1 :(得分:0)

如果您使用https://console.developers.google.com配置了项目 无需在代码中进行任何配置。

默认情况下,对于 ANDROID ,您可以设置3个环境

  1. DEV
  2. 发布
  3. Google Play(生产)

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

对于 IOS

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