Assaf Sheep
Assaf Sheep

Reputation: 583

React Native on Ipad - Error - could not connect to development server

I'm using React-Native, when I run the AwesomeProject with Xcode and iPhone simulator everything works well, but when I connected my iPad and built the project on my iPad I receive an error on the iPad when the app starts:

"Could not connect to development server. Ensure node server is running. The operation couldn't be completed (NSURLErrorDomain error -1004)".

I also ensured that the node package is running. I even restarted Xcode and started it all over with running npm start.

Could you please assist?

Upvotes: 19

Views: 17647

Answers (6)

Seems stupid from my part, but to me ends up that my Smartphone/iPhone was not on the same Router of the PC/Mac. Either the device had the Wi-Fi turned off, nor connected to another router on "bridge mode" of the same network.

SOLUTION: Connect both devices on the exactly same Wi-Fi router.

Upvotes: 0

Ali Mamedov
Ali Mamedov

Reputation: 5256

I have prepared a small instruction which will help to solve this problem.

When your application cannot connect to the server, you will see the message like this:

enter image description here

Open a file AppDelegate.m in your Xcode project and look for

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];

You have to replace this address with your local address.

enter image description here

To look up your local IP address in Mac OS X open Terminal application (located in /Applications/Utilities) and type ipconfig getifaddr en1 for wireless, or ipconfig getifaddr en0 for ethernet.

enter image description here

You can check It in browser. And you will see React Native Debugger page

enter image description here

Just replace localhost in AppDelegate.m with your IP address. localhost to 192.168.1.100 in my case.

enter image description here

Run your application in Xcode again.

Upvotes: 4

Lane Rettig
Lane Rettig

Reputation: 6950

Another potential issue which can cause the exact same error is App Transport Security (ATS) in iOS9--this happened to me, even though everything else was set up correctly. See my description and solution at https://stackoverflow.com/a/34880394/2397068.

Upvotes: 4

MindJuice
MindJuice

Reputation: 4291

In my case, I just had a very old version of node.js installed (version 0.8.6). After updating node.js to version 0.12.2, the default project that react-native init AwesomeProject created worked perfectly.

Upvotes: 0

tadeuzagallo
tadeuzagallo

Reputation: 2522

On your AppDelegate.m you have to update the jsCodeLocation and replace localhost with your machine ip address.

Either that or bundle the compiled source into your application, which is commented as option 2 on AppDelegate.m as well. You download the compiled code, and add it to your Xcode project.

Upvotes: 31

Micael
Micael

Reputation: 6970

Try to take a look here for the solution:

https://github.com/facebook/react-native/issues/240#issuecomment-86977126

Upvotes: 4

Related Questions