简体   繁体   中英

Use Xcode (custom) Build Settings or Preprocessor Directives from bundled javascript

I am making a Cordova (hybrid) iOS app and would like to have some ability to automate changing the contents of one key javascript file contained within the app bundle, depending on whether I'm building for RELEASE or DEBUG.

The javascript code contains the app's server ip address, which I want to automatically switch between the development machine and the production server. The file in question contains other code which often changes, so maintaining two versions of the file would be undesirable.

My Objective C code has no problem with this, I can access the variables directly in code - it just works. Obviously since the javascript files don't get compiled or processed as such, this approach doesn't work. What is the best way to have these Xcode settings propagate to my javascript file(s)?

Thanks for your thoughts :)

edit: Part of the reason we're looking for a solution here is to avoid rebuilding with cordova as much as feasibly possible.

We're in active development and often need to make minor changes to various cordova plugins for performance or compatibility optimisations, and it doesn't make sense for us to maintain forks of the various plugins purely to actively continue using the cordova-cli. (it's a meteor project, which makes things even more convoluted - notably, we can't add plugins from local directories, only direct git tarball links or published plugins)

As an alternative, you could use a cordova hook to copy a debug.json or a release.json file to the target, depending on the build circumstances, to a fixed config.json that your app loads onDeviceReady , and which contains all the specifics (like server address). I have not tried but it looks promising.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM