Undistraction
Undistraction

Reputation: 43402

Switching urls used in an iOS application between local and remote

I have ab iPhone application that makes heavy use of a Rails json API I have built. Most of the time I am testing the local version of my API (URLs like localhost:3000/api/log_in), but I also need to test it on a remote server from time to time (URLs like someapp.com/api/log_in).

How can I easily switch the urls used by my application depending on whether I want to test against my local or remote server?

Upvotes: 1

Views: 155

Answers (1)

Jonas Schnelli
Jonas Schnelli

Reputation: 10005

Okay. You should go like this:

  1. Create another target (by copy the existing one) enter image description here

  2. Under Build Settings, change the Prefix Header to another filename enter image description here

  3. Create the new Prefix Header (just add a file or duplicate/add your existing Header Prefix File) enter image description here

  4. Add the same precompiler constant (#define) to both .pch file. One with your productive URL, one with your localhost URL. Instead of your "static" URL in your code, use the new set precompiler constant.

  5. Now you can switch between localhost/production with switching targets next to your run/stop buttons

enter image description here

Upvotes: 2

Related Questions