【问题标题】:React-Native. Simulator could not connect to development server反应原生。模拟器无法连接到开发服务器
【发布时间】:2016-11-03 19:42:49
【问题描述】:

我尝试更改可以在设备上测试的 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

【问题讨论】:

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 2010-12-31
    • 2021-12-28
    相关资源
    最近更新 更多