DEV Community

charismaaji
charismaaji

Posted on

Setting up for connect fetching local API or http React Native IOS / MacOS

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>


Enter fullscreen mode Exit fullscreen mode

Block this section on plist file, and delete it. After that, you paste from your copying before

Image description

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)