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
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?
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
1...23 <application4 android:name=".MainApplication"5 android:icon="@drawable/icon"6 android:label="@string/app_name"7 android:roundIcon="@drawable/icon"8 android:theme="@style/AppTheme"9 android:requestLegacyExternalStorage="true"10 android:usesCleartextTraffic="true"11 >12 <!--remove this line android:usesCleartextTraffic="true" -->13 ...14 </application>15...
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
1<key>NSAppTransportSecurity</key>2<dict>3 <key>NSAllowsArbitraryLoads</key>4 <true/>5 <key>NSExceptionDomains</key>6 <dict>7 <key>localhost</key>8 <dict>9 <key>NSExceptionAllowsInsecureHTTPLoads</key>10 <true/>11 </dict>12 </dict>13</dict>
NSAppTransportSecurity on info.plist file remove key dict pair and test your app.
Thanks for reading…
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.