1

Background

I am developing an iOS app that connects to a server. We have a team of developers who run their own server with unique addresses for debugging. Our rule for source control is to only checkin the "production url".

In Android we have a solution that works really well. This solution won't work in iOS.

What I've Tried

Set a "Command line argument" or "Environment variable" in the Build Scheme. The problem with this is those are put into the "*.xcproject" file which get's checked in and causes merge conflicts. If it could be set at the user level it would be fine because we .gitignore xcuserdata.

I also tried referencing a "MyConfig.h" file that does not get checked in. But if it does not exist the project won't build.

What I want to do

If a developer wants to point at a different server they would set an environment variable on their mac. Something like "export MY_SERVER="http://domain.com/api/". In the project file we would add and environment or command line argument that is basically "MY_SERVER=$(MY_SERVER)".

Unfortunately I can't figure out how to get XCode to resolve the variable on my OSX machine. It seems environment variables are resolved on the device only. Command line arguments seem to be taken literally.

Research I've done

http://qualitycoding.org/production-url/ - does not really address the real issue

http://nshipster.com/launch-arguments-and-environment-variables/

Google, Apples developer forum and Stackoverflow post.

How do you do this in your projects ?

Is the only solution to use a backdoor or some file folks change and just try not to accidentally checkin?

Marco
  • 6,692
  • 2
  • 27
  • 38
Yepher
  • 1,465
  • 12
  • 25
  • You can create separate `development` and `production` targets in Xcode. These can have separate `MY_SERVER` build settings environment variables to point to your backend https://stackoverflow.com/a/74254208/4975772 – joshuakcockrell Nov 09 '22 at 04:47

1 Answers1

0

As an update I found the solution that solves the problem for me. I am using https://github.com/xslim/mobileDeviceManager and a script that is checked in. The developer can create their custom configuration and copy it to the documents directory. Now we keep production checked in and have a runtime check for our custum configuration file.

Here is an example of the tools usage:

$ mobileDeviceManager -o copy -app "com.domain.MyApp" -from ~/.myAppConfig/app_override.plist

This way the developer can keep their custom configuration in their home directory (out of source control) without fear of accidental checkin. We already use process like this for other desktop and android apps so this fits our process really well. This has the added benefit that if a testers device is failing we can point it at a custom debug server with extra logging to simplify the debug process and not need to deploy a new binary to that device during internal testing.

I hope this can help someone else.

Yepher
  • 1,465
  • 12
  • 25