【发布时间】:2019-05-29 20:04:02
【问题描述】:
在本机开发中,我根据构建“风味”在 firebase 生产和开发项目之间切换我的应用程序。
在 Android 上,我将 google-services.json 放在文件夹中
<ProjectDir>/app/src/<BuildFlavour>
BuildFlavour 可以是例如debug 或release。
因此对于 Flutter 项目也可以轻松完成。我确实看到了:
> Task :app:processDebugGoogleServices
Parsing json file: /Users/shadowsheep/AndroidStudioProjects/flutter_app_test_fcm_messaging/android/app/src/debug/google-services.json
在 iOS 上我会这样做:
NSString *googleFirebaseJsonFileName = @"GoogleService-Info";
#ifdef DEBUG
NSLog(@"[FIREBASE] Development mode.");
googleFirebaseJsonFileName = @"GoogleService-Info-Debug";
#else
NSLog(@"[FIREBASE] Production mode.");
#endif
NSLog(@"%@", googleFirebaseJsonFileName);
NSString *googleFirebaseJsonFilePath = [[NSBundle mainBundle]
pathForResource:googleFirebaseJsonFileName
ofType:@"plist"];
NSLog(@"%@", googleFirebaseJsonFilePath);
// https://firebase.google.com/docs/cloud-messaging/ios/client
FIROptions *options = [[FIROptions alloc]
initWithContentsOfFile:googleFirebaseJsonFilePath];
[FIRApp configureWithOptions:options];
如何在 Flutter 中为 iOS 项目以正确的方式实现这一目标?我必须把这个确切的代码放在AppDelegate 里面吗?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
// I've to init Firebase here the same way?
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
【问题讨论】: