2016-06-28 55 views
18

我有一个应用程序,即时通讯使用提取认证用户。它一直在工作到几天前,我没有改变任何东西。刚刚从反应0.27升级到0.28,没有获取不工作。React-Native提取,网络请求失败。不使用本地主机

我已经搜索了近2天,我已经阅读了几乎所有的问题在stackoverflow。大多数用户试图从本地主机获取某些内容,并且当他们将其更改为实际的IP地址时,他们就可以使用它。 但我没有从本地主机获取任何东西,也是我的代码曾经工作。

这里是我的代码:

fetch('http://somesite.com/app/connect', { 
 
     method: 'POST', 
 
     headers: { 
 
     'Accept': 'application/json', 
 
     'Content-Type': 'application/json', 
 
     'language':'en-US', 
 
     'Authorization': 'Bearer ' + access_token, 
 
     }, 
 
     body: JSON.stringify({ 
 
     uid: uid, 
 
     refresh_token: refresh_token, 
 
     token: access_token, 
 
     device: device_id, 
 
     device_name: device_name, 
 
     }) 
 
    }) 
 
.then((response) => response.json()) 
 
.then((responseData) => { 
 
    console.log(JSON.stringify(responseData.body)) 
 
}) 
 
.catch((err)=> { 
 
    console.log('Some errors occured'); 
 
    console.log(err); 
 
}) 
 
.done();

我试图做一些新的项目,简单,只需用一个简单的例子取来回教程,它给了同样的错误。我试图打开我的网站,即时尝试连接到它,通过模拟器中的浏览器,它的工作原理,但似乎通过我的应用程序无法连接到任何网站/ IP。它给这个错误在Chrome控制台:

TypeError: Network request failed 
    at XMLHttpRequest.xhr.onerror (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:28193:8) 
    at XMLHttpRequest.dispatchEvent (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:14591:15) 
    at XMLHttpRequest.setReadyState (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:29573:6) 
    at XMLHttpRequest.__didCompleteResponse (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:29431:6) 
    at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:29506:52 
    at RCTDeviceEventEmitter.emit (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:13428:23) 
    at MessageQueue.__callFunction (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11999:23) 
    at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11906:8 
    at guard (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11857:1) 
    at MessageQueue.callFunctionReturnFlushedQueue (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11905:1) 

其实我有同样的问题,因为该用户的位置:React-native network request always fails

UPDATE: info.plist from xcode

任何帮助将不胜感激!

+0

你有没有在'NSAppTransportSecurity'在你的应用程序的Info.plist文件是什么? –

+0

感谢您的回复。我已将屏幕截图添加到主帖子中。你也可以在这里看到http://i.stack.imgur.com/vvqMk.png – Ataomega

+0

@Ataomega你有没有尝试重新启动你的电脑?我有这个相同的问题,只是一个简单的重新启动修复它。 –

回答

46

你应该看看这个链接:https://github.com/facebook/react-native/issues/8118

看起来问题出现在本机作出反应0.28。解决方法是在React创建的ios> build文件夹中找到的info.plist文件中“允许任意加载”。

如果你打开xcode中的整个ios文件夹,然后打开这个info.plist文件,你可以创建一个新的密钥允许任意负载,它应该可以解决你的问题。

Allow Arbitrary Loads

+1

问题已经解决了,谢谢反正 – Ataomega

+1

@Ataomega你是怎么解决这个问题的呢我在andriod中面对同样的问题 – Carlos

+0

@Carlos作为最后答案说... – Ataomega

相关问题