2016-07-01 110 views
1

我试图更改我可以在设备上测试的ip地址。React-Native。模拟器无法连接到开发服务器

在更改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

我也试着打开这个IP在Safari模拟器:http://joxi.ru/RmzQBJKHWkJVOr

解决方案: 我不得不使用react-native start个不NPM开始

+0

,我可以首先看你有没有解决_App传输安全已阻止明文HTTP_此问题。按照这个_ [传输安全已经阻止了明文HTTP](http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http)_。 –

回答

0

您还需要添加NSAllowsArbitraryLoads键在Info.plist中,旁边NSExceptionDomains关键,就像这样:

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