I have been developing a new iOS app using React Native. I have been testing it using simulator provided by Xcode. Now it’s time to test the app using a real device. One could ask why test on a real device if it works perfectly on a simulator. Here are some of the reasons.
- There are a number of device specific features which are not testable on a simulator. Phone calls, camera, gps data, compass and vibration are a few of them.
- Testing unexpected cases that can only be tested on a real device. Like how your application handles incoming calls, low memory situations, low disk space, limited data connectivity etc.
- Hardware-wise, your device is different than your Mac. If your app is graphics intensive and requires a lot of CPU usage, it might work seamlessly on your simulator depending on your Mac’s specifications. But it might be laggy and glitchy on the real device.
Now let’s look into how you can start testing your React Native app on an real iPhone.
Step 1 - Plug in your device
Plug in your device to your Mac and open Xcode. You will be able to select your device to the right of the Play and Stop buttons.
You might run into one of the following two errors if you have not enrolled into Apple’s Developer Program.
Error 1 : Failed to code sign
To fix above issues please enroll in Apple Developer program.
Error 2 : Disk Image could not be mounted
This can happen if your iOS version is not supported by your current version of Xcode. To fix this, just update your Xcode to the latest version from the App Store.
Step 2 - Set right deployment target
In your Xcode project setup the
Deployment Target should be set to less than or equal to the iOS version installed on the device.
If your iPhone is running iOS 7.0 and you have set “Deployment Target” as 8.0 then the app will not work. If your iPhone is running iOS 8.0 and you have set “Deployment Target” as 7.0 then the app will work.
Step 3 - Fix “Could not connect to development server” error
So the app is installed and you can see the launch screen. That’s great. But soon you might get following error on your iPhone.
<img src=”/assets/testing_ios_app/connection-error-cf34a1f8eb8059baa422955e6a5c8361da648cf7564c657d469515eeb5e9b6f2.PNG” alt=”connection error” width=200=”true” height=350=”true” width=”640” height=”1136”>
To fix this open
AppDelegate.m file in your project’s iOS folder.
Locate line mentioned below and replace
localhost with your Mac IP address e.g.
To find the ip address of your Mac this is what ReactNative suggests us to do.
you can get ip by typing
ifconfiginto the terminal and selecting the *
Save and click run again. This will fix the error.
Step 3 - Fix connecting to API hosted on local development server
Now the app is installed and you can navigate through the app screens. If the app attempts to make API call to the server running locally on the machine then depending on how the local server was started it could be a problem.
In my case, I have a Ruby on Rails application running on my local machine.
I had started my rails server by executing command
To do this, the app should be able to access the rails server using the private ip of the server e.g.
Turned out that I had started my rails server using command
change in Rails 4.2
rails server listens to
localhost and not
The rails guide further says following.
with this change you will no longer be able to access the Rails server from a different machine, for example if your development environment is in a virtual machine and you would like to access it from the host machine. In such cases, please start the server with rails server -b 0.0.0.0 to restore the old behavior.
In this case iPhone is trying to talk to Rails server so Rails server must be started using following command.
By doing so, now you can connect to your Rails app from your local network, by browsing to
These were some of the issues I came across while testing my iOS app on an actual device and how I fixed them. Hopefully, this blog post helps you fix these error cases get you started on testing quickly.