如何根据构建配置将命令行参数传递给 Xcode

How to pass command line argument to Xcode based on build configuration

我想添加 -FIRDebugEnabled 参数以在 Firebase 控制台上启用调试视图,但仅当它是调试或暂存构建时。

我尝试在 application didFinishLaunchingWithOptions 中添加 CommandLine.arguments.append("-FIRDebugEnabled") 但这似乎不起作用,所以我认为我需要在构建阶段或发布方案中的预操作中添加它。但是我想不通。

提前致谢!

如果我理解正确,添加到方案的启动参数仅在从 Xcode 直接构建应用程序到设备或模拟器时设置。如果您希望在其他情况下设置 FIRDebugEnabled(以便在用户在实际设备上启动应用程序时也设置它),也许这会起作用:

var newArguments = ProcessInfo.processInfo.arguments
newArguments.append("-FIRDebugEnabled")
ProcessInfo.processInfo.setValue(newArguments, forKey: "arguments")