2016-07-01 109 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> 
相關問題