try 使用react-native-config.这里还有一篇关于Managing Configuration in React Native与react native config的好文章.
我在这里给出了一个在测试过程中如何使用配置来禁用animated-button-block-the-detox动画的例子.
基本的 idea 是你创造.用于所有不同构建环境(开发、生产、测试等)的环境配置文件.它们保存了您可以从中访问的配置变量 Javascript、Objective-C/Swift或Java.
然后指定哪个.构建应用程序时要使用的环境配置文件:
$ ENVFILE=.env.staging react-native run-ios # bash
这是包装的一个例子.Detock使用的json文件.用于构建应用程序的环境配置文件.
"detox": {
"specs": "e2e",
"configurations": {
"ios.sim.release": {
"binaryPath": "ios/build/Build/Products/Release-iphonesimulator/example.app",
"build": "ENVFILE=.env.production export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -project ios/example.xcodeproj -scheme example -configuration Release -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"name": "iPhone 5s, iOS 10.3"
},
"ios.sim.test": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/example.app",
"build": "ENVFILE=.env.testing xcodebuild -project ios/example.xcodeproj -scheme example -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build -arch x86_64",
"type": "ios.simulator",
"name": "iPhone 5s, iOS 10.3"
}
}
}