Raymon Schouwenaar

React Native on iOS: Network Request Failed

Written by Raymon on , time to read ~1 minutes.

By default iOS isn’t supporting HTTP requests, only HTTPS requests are allowed.

But what if you have an API that only works with HTTP, you can easily change the setting’s to support HTTP requests.

When I first tried to do a request to an HTTP address it gave me the error “Network Request Failed”. I couldn’t get why.

But after some digging, I figured iOS was only supporting HTTPS.

To change this, open the “info.plist”. You can find this at ‘ios/ProjectName’.

Search for <key>NSAppTransportSecurity</key>. If it’s there already you only need to this code below it:

<br /><dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Now close your simulator and kill the running process (if you already started it). Run react-native run-ios again, and now your iOS app will support HTTP calls.

Hope this will help to fix your problem with React Native 🙂

comments powered by Disqus

Readmore

CSS Grid Layout Metro design blocks

The times have come that we don’t have to fiddle around with Floats and Tables anymore! Flexbox is already an established term in the industry of Frontend Developers.

3 ways to loop over Object properties with Vanilla JavaScript

It happens a lot that you need to loop over an Array with JavaScript Objects! But sometimes you just don’t know what kind of properties that Object has. Lucky we are that JavaScript offers a few ways of looping over JavaScript Object properties.