Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot load HTTP links in UIWebView in iOS 9

I am trying to load HTTP links within UIWebView. The links are from my website so they are reliable. I have searched the internet and found the solution here: How can I add NSAppTransportSecurity to my info.plist file?

After following that solution my info.plist looks like this.:

enter image description here

Even after making the changes I cannot load HTTP links within UIWebView. I get the following error:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure

Is there something I am doing wrong?

UPDATE:

After making the changes suggested by Ramshad in comments it still does not work. See image below:

enter image description here

like image 247
Skywalker Avatar asked Sep 21 '15 08:09

Skywalker


People also ask

Which browser is used in iOS WebView?

Safari browser installed in iOS & webview browser (if safari) are same or there are difference?

Does WebView work on iOS?

WKWebView replaces the UIWebView class in iOS 8 and later, and it replaces the WebView class in macOS 10.10 and later. Embed a WKWebView object programmatically into your view hierarchy, or add it using Interface Builder.

How do I enable WebView on my Iphone?

First, enable the Safari Web Inspector on your iOS device by opening the iOS Settings app, navigating to Settings > Safari > Advanced, and toggling the Web Inspector option on.

Is UIWebView deprecated?

As of iOS 12.0, 'UIWebView' has been explicitly marked as deprecated. Apple is encouraging developers to adopt WKWebView instead, which was introduced in iOS 8.0.


1 Answers

Check this article: link.

App Transport Security (ATS) normally doesn’t allow our apps to connect to HTTP servers, but there’s a special exception you can add to allow UIWebView and WKWebView to load insecure content.

TL;DR

Just add to your .plist file:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
</dict>

NSAllowsArbitraryLoadsInWebContent is available from iOS 9.0 so should be fine for you.

like image 109
Kamil Harasimowicz Avatar answered Sep 28 '22 08:09

Kamil Harasimowicz