Some of you maybe got confused, why the API doesn’t work and get error when try to connect to local API or maybe http instead https.
It because by default React Native cannot connect to API with http request, it's should be https
To solve this problem, you need a bit setup on plist file
first go to folder
ios > {your file name} > info.plist
for example
ios > FashionApp > info.plist
after that you copy this file
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Block this section on plist file, and delete it. After that, you paste from your copying before
Success, now you can connect with http or local host without get any errors.
If you have any question, feel free to ask me on
email : charismakurniawan@gmail.com
instagram : charismaaji
Top comments (0)