DEV Community

charismaaji
charismaaji

Posted on

3 2

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post