Giesburts
Giesburts

Reputation: 7648

Network requests failed with React Native Expo on iOS

There are questions that are related but none of them answered my question so I thought let's ask it myself with some details.

I am working with a React Native build with the Expo SDK. I am using a localhost GraphQL API but it seems that iOS prevents fetching data from http endpoints. According to sources and other related questions, you have to add stuff to your info.plist file in your iOS build.

But since I am using the Expo SDK I don't have my iOS build. According to the docs, you can add a infoPList object to your app.json. This answer suggests that as well.

So I added in my app.js the following but that didn't worked out:


"ios": {
    "supportsTablet": false,
    "infoPlist": {
        "NSAllowsArbitraryLoads": {
            "NSAllowsArbitraryLoads": true
        }
    }
}

I am still getting the same "Network request failed" error. Does someone know the solution to this without ejecting?

Upvotes: 0

Views: 4439

Answers (2)

Aniss_fullstack
Aniss_fullstack

Reputation: 11

I had exactly the same problem, I use fetch () to send my data from my native react application to my php server, I simulate from my IOS phone with expo but I receive the same error as you while I have configured the correct IPV4 address (fetch (http: // ipv4 address / ...) ) and not localhost... Also when I simulate a web view on my pc and I put fetch (http: // localhost / ..), I receive the data everything works perfectly ..

Upvotes: 0

Yongzhi
Yongzhi

Reputation: 1070

The issue is that localhost on your device does not point to your local dev server, which is on another machine. To fix this, you should make sure that your testing mobile device and dev server are under the same local network, and change localhost to the ip of dev server machine.

Upvotes: 2

Related Questions