In this post we will fix the Network request failed error in iOS simulator that is common for many React Native new-comers.
NOTE: this article is related to environment issue, but request may also fail because of badly configured ajax call.
A lot of people that dives into React Native get stuck when trying to make a simple HTTP GET-request. And there can be much more than one reason for that but let’s look to the most common mistake that causes the failure of network request.
Fixing ‘Network request failed’ error
First of all, when you try to use the network in your app, you should enable it in XCode.
- Click on your project in the Project Navigator
- Open the Info tab
- Right click on App Transport Security Settings and select Add Row
- For created row set the key “Allow Arbitrary Loads“, type to boolean and value to YES.
After that rebuild your project and the network request should pass successfully.