Ivo Dimitrov Ivo Dimitrov - 5 months ago 565
Node.js Question

React-Native. Simulator could not connect to development server

I tried to change ip address that I could test on the device.

After changing lines in AppDelegate.m I did rebuild the application and restarted the server (npm start).

As you can see, the server is visible from the browser, everything works fine, but inside the app says that cannot connect to the server.

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


After restart project I see:

2016-07-01 13:12:07.949 PropertyFinder[10626:5440580] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
2016-07-01 13:12:09.964 [fatal][tid:main] Could not connect to development server.

Ensure the following:
- Node server is running and available on the same network - run 'npm start' from react-native root
- Node server URL is correctly set in AppDelegate

URL: http://192.168.1.1:8081/index.ios.bundle?platform=ios&dev=true


Screenshot: http://dl2.joxi.net/drive/2016/07/01/0001/2707/121491/91/faf405e34d.png

I also tried open this ip in Safari Simulator: http://joxi.ru/RmzQBJKHWkJVOr

Solution:
I had to use react-native start not npm start

Answer

You also need to add the NSAllowsArbitraryLoads key in Info.plist, next to the NSExceptionDomains key, like this:

<key>NSAppTransportSecurity</key>
<dict>
 <key>NSExceptionDomains</key>
 <dict>
   [...]
 </dict>
 <key>NSAllowsArbitraryLoads</key>
   <true/>
</dict>
Comments