FirebaseからダウンロードしたGoogleService-Info.plistを環境ごとに切り替えるコードを紹介します.
Swift版はこちらを参考にしてください.
→FirebaseをStaging環境とかDebug環境とかRelease環境で切り替えをする
今回はDebugの場合とReleaseの場合とその他の場合でplistを分岐させます.
Debug → GoogleService-Info-Debug.plist
Release → GoogleService-Info-Release.plist
その他 → GoogleService-Info.plist
コード例
普段,[FIRApp configure]で済ませる箇所にoptionを追加します.
AppDelegate.h
#import <UIKit/UIKit.h>
#import "Firebase.h" // ←追加部分:Firebaseをインポートする
@interface AppDelegate : UIResponder <UIApplicationDeledate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
#import "AppDelegate.h"
/*
* 環境ごとに使用するplist名を定義しておく
* plist名 → firebasePlistName
*/
#ifdef DEBUG
static NSString * const firebasePlistName = @"GoogleService-Info-Debug";
#elif RELEASE
static NSString * const firebasePlistName = @"GoogleService-Info-Release";
#else
static NSString * const firebasePlistName = @"GoogleService-Info";
#endif
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSString *filePath =[[NSBundle mainBundle] pathForResource:firebasePlistName ofType:@"plist"];
FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
[FIRApp configureWithOptions:options];
return YES;
}
・
・
・
@end
こんな感じで環境ごとにplistを切り替えることができます.
環境別に分析したいという時にお役に立てれば幸いです.