在我的项目中,对于具有不同配置(生产/暂存/质量检查)的同一应用程序,我有不同的目标。根据Firebase docs的建议,我为每个trarget添加了一个plist
文件,并通过以这种方式传递正确的配置文件来初始化FirebaseApp:
let configPath = Bundle.main.path(forResource: NAME_OF_PLIST_FOR_CURRENT_TARGET ofType: ".plist")!
let options = FirebaseOptions(contentsOfFile: configPath)!
FirebaseApp.configure(options: options)
我还根据文档here中的建议从项目中删除了
GoogleService-Info.plist
文件,以确保可靠的Google Analytics(分析)报告。当我在控制台中运行该应用程序时,我会看到这些消息。
[Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
[Firebase/Analytics][I-ACS020006] Google App ID from GoogleService-Info.plist is empty. Please, define GOOGLE_APP_ID in GoogleService-Info.plist for Analytics to work reliably. See
[Firebase/Analytics][I-ACS025020] Analytics requires Google App ID from GoogleService-Info.plist. Your data may be lost. Google App ID has been changed. Original, new ID: (nil), MYAPPID
难道我做错了什么?这种配置会导致丢失Analytics(分析)吗? (如控制台消息所建议)
最佳答案
经过几次尝试后,尽管控制台中出现错误消息,但Firebase似乎配置正确。
尽管如此,我还是决定采用@Micgal提出的解决方案,因此在单独的文件系统目录中有多个名为GoogleService-Info.plist
的文件,并将每个文件添加到相应的目标中。然后,我可以使用FirebaseApp.configure()
初始化Firebase,它可以按预期工作,而不会生成错误消息。