Setting debug server URL for running app on device for iOS/Xcode.

Karun Pant
Mar 21, 2018 · 3 min read
Xcode + React native

When using react native with Xcode, we faced a problem that it doesn’t run on your device with localhost kind of URL(s), you need to put your debug server’s IP if you want to use the app on your device.

I tried using strings file [Very bad Idea] to read a property and git-ignore it so other devs don’t get affected by your IP change. But guess what I ignored the fact that it’s a project file and xcproj file will still track it, which landed me into issues with CI server which didn’t had this file but xcproj was asking for that file. Then, I found this awesome article by Derrick Ho, which talks about the use of environment variable for dynamic binding data you need on runtime like debug URL.

Here’s what I did:

Create a new scheme for your app I named it “[MyAppName]debug”. For this go to “Schemes” menu on the top right and select “New Scheme”

Create new scheme
Name the scheme <Your project name> Debug

Now go to “Manage Schemes” from the “Schemes” menu , and ensure sharing is off for the scheme or it will attach itself to proj file and it will be tracked on git.

Shared should be unchecked

Now go to “Edit Scheme” from the “Schemes” menu, select “Run” from left side tab. And find “Environment Variables” section in “Arguments” tab. Set a URL with your debug server’s IP and full path of your jsbundle file.

Phew, with this first and most hectic part is done. Now somewhere in your util class add the following piece of code

Get debug URL from environment var serve

Pay attention to the code where I save this URL to persistent storage this is because as soon as you terminate the session with Xcode you will not get environment vars from Xcode on next launch of app. And you will land back to local host this piece of code prevents that, and also it’s happening only for debug so it will not affect your users.

And that’s it, you’re done just call <yourUtilClass>.jsCodeLocation anywhere and you will get your URL dynamically from environment var you just created.

Cool right.

Psst… Make sure everyone in your team follows these steps with their ip. And all set now no one need to worry about debug server’s IP anymore while developing.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade