1
正如許多人在回答類似的問題建議的成功,我已經編輯info.plist
加入我:陣營本地網絡請求在iPhone上失敗,但在iPhone模擬器
<key>NSAllowsArbitraryLoads</key>
<true/>
一切工作完全正常的iPhone模擬器,但是當我試圖讓我的iPhone的網絡請求,我得到這個錯誤在遠程調試器:
TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (fetch.js:441)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:542)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:378)
at XMLHttpRequest.js:482
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:236)
at MessageQueue.js:108
at guard (MessageQueue.js:46)
at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:107)
我已經重新啓動Xcode的次數比我現在可以計算的更多。我從來沒有與任何其他應用程序的這個問題。這裏從請求的代碼,錯誤源於從底部第二catch
:
loginFinished (error, result) {
if (error) {
console.log(error)
alert("Login failed with error: " + error);
} else if (result.isCancelled) {
alert("Login was cancelled");
} else {
AccessToken.getCurrentAccessToken()
.then(response => {
console.log('1',response)
fetch(`http://localhost:3000/auth`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
fbAccessToken: response.accessToken
})
})
.then(response => response.json())
.then(data => {
console.log('data: ', data)
this.props.setUser(data)
})
//Network error comes from this catch
.catch(err => console.log(err))
})
.catch(err => console.log(err))
}
}