如何在单个iOS项目/应用中为发布和调试模式(测试和生产环境)创建不同的Firebase数据库



现在我们正在处理在iOS应用中使用Firebase实时数据库的项目。是否可以在单个 iOS 应用中为发布和调试模式创建不同的 Firebase 数据库?

项目:(具有发布/调试模式的应用(

  1. 调试模式(测试环境( - Firebase 数据库 1
  2. 发布模式(生产环境( - Firebase Database 2

解决Firebase数据库的测试/生产环境的最佳建议是什么?

如果你使用不同的数据库进行调试和发布构建,那么你必须注意以下事情。我认为这不是一个好主意。

1( 相应的 .plist 文件应该在项目中。

2( 根据基本 URL 添加/删除。

上述问题的最佳方法。

假设您的基本网址为:https://xxxxxxx.firebaseio.com

对于调试版本:- https://xxxxxxx.firebaseio.com/Debug

对于发布版本:- https://xxxxxxx.firebaseio.com

最后通过两个简单的步骤解决

第 1 步:将 GoogleService-Info-dev.plist 和 GoogleService-Info.plist 复制到项目工作区。

第 2 步:只需根据 didFinishLaunchingWithOptions 中的调试/生产环境更改 ...-Info.plist

/* 
* Here in  didFinishLaunchingWithOptions method,
* just change the *...info.plist* file path according to the requirement
*/
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // DEBUG ENVIRONMENT
    //let filePath = Bundle.main.path(forResource: "GoogleService-Info-dev", ofType: "plist")! 
    // PRODUCTION ENVIRONMENT
    let filePath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist")! 
    let options = FIROptions(contentsOfFile: filePath)
    FIRApp.configure(with: options!)
    return true
}

相关内容

最新更新