iosreact-native

React-Native: Problems with Axios on iOS


I'm using ReactNative keep getting a network error on every Axios Request on iOS.

Error: Network Error
    at createError (createError.js:16)
    at XMLHttpRequest.handleError (xhr.js:81)
    at XMLHttpRequest.dispatchEvent (event-target-shim.js:818)
    at XMLHttpRequest.setReadyState (XMLHttpRequest.js:574)
    at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:388)
    at XMLHttpRequest.js:501
    at RCTDeviceEventEmitter.emit (EventEmitter.js:189)
    at MessageQueue.__callFunction (MessageQueue.js:436)
    at MessageQueue.js:111
    at MessageQueue.__guard (MessageQueue.js:384)

Apparently, iOS doesn't allow APIs that don't use HTTPS to run, but as per my research, updating Info.plist should have done the trick. Here's how I have updated it:

enter image description here

The android version of this application works perfectly fine. Any suggestions?


Solution

  • The problem was pretty simple. My server is hosted on localhost, and you need to use an IP/hostname that is not 127.0.0.1/localhost. Find your private IP address and start your server on that and reference that in react-native. However, 127.0.0.1/localhost works fine on Android.

    A live server should work too as long as you use HTTPS or allow ignoring HTTPS in your Info.plist file available in your iOS project workspace.