我想在同一个项目中为不同的环境设置不同的google-service-plist文件,以便进行防火墙集成。
发布于 2019-10-23 08:21:47
struct Configuration {
static var environment: Environment = {
return Environment.init(rawValue: Bundle.main.object(forInfoDictionaryKey: "Configuration") as! String)!
}()
static var documentsDir: String {
guard let dir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first else { fatalError("There was something wrong finding the documents directory") }
return dir
}
}
enum Environment: String {
case local = "Local"
case production = "Production"
var googlePlistFileName: String {
switch self {
case .local:
return "GoogleServiceMobileLocal"
case .production:
return "GoogleServiceMobileProduction"
}
}
}I在信息plist文件中添加了一个键

发布于 2019-10-23 06:29:33
这是objc解决方案,但是它可以很容易地转换成Swift,我希望它会有所帮助:
NSString *filePath;
#ifdef DEBUG
filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Staging" ofType:@"plist"];
#else
filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Production" ofType:@"plist"];
#endif
FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
[FIRApp configureWithOptions:options];发布于 2019-10-23 08:52:43
#if DEBUG
let path = Bundle.main.path(forResource: "GoogleService-Staging", ofType: "plist")
#else
let path = Bundle.main.path(forResource: "GoogleService-Production", ofType: "plist")
#endif
if let options = path.flatMap({ FirebaseOptions(contentsOfFile: $0) }) {
FirebaseApp.configure(options: options)
} else {
// handle failed configuration here
}https://stackoverflow.com/questions/58516306
复制相似问题