反应母语。模拟器无法连接到开发服务器

时间:2016-07-01 11:46:53

标签: ios node.js reactjs npm react-native

我试图更改我可以在设备上测试的IP地址。

在更改AppDelegate.m中的行后,我确实重建了应用程序并重新启动了服务器(npm start)。

正如您所看到的,服务器在浏览器中可见,一切正常,但在应用程序内部表示无法连接到服务器。

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

重新启动项目后,我看到:

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

屏幕截图:http://dl2.joxi.net/drive/2016/07/01/0001/2707/121491/91/faf405e34d.png

我也试过在Safari模拟器中打开这个ip:http://joxi.ru/RmzQBJKHWkJVOr

解决方案: 我不得不使用 react-native start 而不是 npm start

1 个答案:

答案 0 :(得分:0)

您还需要在InfoExplist中的NSExceptionDomains键旁边添加 NSAllowsArbitraryLoads 键,如下所示:

<key>NSAppTransportSecurity</key>
<dict>
 <key>NSExceptionDomains</key>
 <dict>
   [...]
 </dict>
 <key>NSAllowsArbitraryLoads</key>
   <true/>
</dict>
相关问题