React Native在iOS真机运行的错误:Could not connect to development server.

前端之家收集整理的这篇文章主要介绍了React Native在iOS真机运行的错误:Could not connect to development server.前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、URL地址设置

问题:

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://localhost:8081/index.ios.bundle?platform=ios&dev=true
2016-08-29 17:52:29.307 [error][tid:main][RCTWebSocketManager.m:84] WebSocket connection Failed with error Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused"


解决:

AppDelegate.m文件中,把一下代码中的localhost改为你电脑的IP地址,并且保证连接的是同一个网络(例如:连接同一个路由的网络)。

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

2、HTTP设置

2016-08-29 18:01:20.273 AwesomeProject[688:263429] 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-08-29 18:01:20.316 [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://10.240.139.46:8081/index.ios.bundle?platform=ios&dev=true

开启ATS即可

猜你在找的React相关文章