React-native IOS: Network request failed
Ok thanks to @while1's answer above, I found the answer that worked for me.
The code in my question above is fine. I had to change the info.plist
file.
Wow what a pain in the ass apple are, why would they complicate things so extremely?
I basically added the following to the info.plist
file.
<key>NSAllowsArbitraryLoads</key>
<true/>
Like this:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
See more info on this in the link in @while1's answer above.
You will need to change your NSAppTransportSecurity policy in info.plist. By default in ios 8 and greater plaintext request are blocked. See Transport security has blocked a cleartext HTTP
your code looks familiar to me seems you're learning Build apps with react native course offered by Stephen Grider.
Even i had this issue.
include delete GLOBAL.XMLHttpRequest;
at the beginning of api.js file.
Like this:
delete GLOBAL.XMLHttpRequest;
var _ = require('lodash');
var rootUrl = 'http://api.openweathermap.org/data/2.5/weather?APPID=xxxxxxxxxxxxxxxxxxxxxx';