Hello Friends,

Welcome To Infinitbility!

React Native provide default block all unsecure or not encrypted url but we made changes on project to call unencrypted url for development and when we want to deploy then we have to re-block unencrypted url calls, this article help you to reblock unsecure urls.

Let start today’s topic How to block calling unencrypted URL in react native

Introduction

We wil remove code on react native to block calling unsecured url and those code are we added when we want to call not encrypted url. then first we understand what are unsecured and unencrypted url?

unsecured and unencrypted urls are those who haven’t ssl certificate they looks like ( http://example.com ) and secured and encrypted url looks like ( https://example.com ) the diffrance is S.

Block unencrypted url in android

React Native provide android:usesCleartextTraffic="true" for allow unencrypted url in android then you have to remove android:usesCleartextTraffic="true" from AndroidManifest.xml ( project/android/app/src/main/AndroidManifest.xml ). it’s something looks like

...

    <application
        android:name=".MainApplication"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:roundIcon="@drawable/icon"
        android:theme="@style/AppTheme"
        android:requestLegacyExternalStorage="true"
        android:usesCleartextTraffic="true" 
        >
        <!--remove this line android:usesCleartextTraffic="true"   -->
        ...
    </application>
...

Block unencrypted url in iOS

React Native provide NSAllowsArbitraryLoads for allow unencrypted url in iOS then we have to remove from info.plist ( project/ios/project/info.plist ). it’s looks something like

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

Search NSAppTransportSecurity on info.plist file remove key dict pair and test your app.

Thanks for reading…