本文介绍了如何根据建筑风格在开发和生产火力基地项目之间进行选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在本机开发中,我会根据构建风味"在Firebase生产和开发项目之间切换应用程序.
In native development I switch my application between firebase production and development project depending on build "flavour".
在Android上,我将google-services.json
放在文件夹中
On Android I put google-services.json
inside the folder
<ProjectDir>/app/src/<BuildFlavour>
例如,BuildFlavour
可以是debug
或release
.
因此,对于Flutter项目,也可以轻松地做到这一点.我确实知道:
So that could be easily done also for a Flutter project. Indeed I see:
> Task :app:processDebugGoogleServices
Parsing json file: /Users/shadowsheep/AndroidStudioProjects/flutter_app_test_fcm_messaging/android/app/src/debug/google-services.json
在iOS上,我将改用这种方式:
On iOS I'll do it this way instead:
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
里面吗?
How can I achieve this in Flutter the right way for iOS project? I've gotta put this exact code inside AppDelegate
here?
- (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];
}
推荐答案
最终我做到了:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
NSString *googleFirebaseJsonFileName = @"GoogleService-Info";
#ifdef DEBUG
NSLog(@"[FIREBASE] Development mode.");
googleFirebaseJsonFileName = @"GoogleService-Info-Debug";
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];
if ([FIRApp defaultApp]) {
NSLog(@"Firebase already configured!");
[[FIRApp defaultApp]
deleteApp:^(BOOL success) {
if (success) {
NSLog(@"Reconfigure Firebase");
[FIRApp configureWithOptions:options];
}
}];
} else {
[FIRApp configureWithOptions:options];
}
#else
NSLog(@"[FIREBASE] Production mode.");
#endif
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
似乎可行.
这篇关于如何根据建筑风格在开发和生产火力基地项目之间进行选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!