iOS WKWebView doesn't load http web content - ios

WKWebView doesn't load http requests, only https is working. My Url's strings are fetched from an API, so the url's links could be http and https. I did read about security, however the only thing I found was to add the following lines to the Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key> NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
However, in the .plist these keys don't exist. Is there any way to make WKWebView load http web content, and would the app be approved by the App Store?
I'm using Xcode 9.

1: Open your info.plist file from the project
2: add App Transport Security Settings in Information Property List
3: add Allow Arbitrary Loads in App Transport Security Settings
See the attached images

You can ignore all transport security restrictions with the key your provided using the following:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
I assume your example is not working due the space in the key:
<key> NSAllowsArbitraryLoadsInWebContent</key>
Try to use the same value as you did but without the space.

Related

Fetch (or Axios) in react native not working for expo for iOS apps

iOS doesn't allow to navigate to http only url, allowing only https.
There is a solution, which is changing some code inside info.plist file
https://github.com/facebook/react-native/issues/8717
How can I change settings for iOS, as it comes with only .expo folder but nothing else.
Do I need to change server configuration for this at last? :(
As you properly find out, the problem is that iOS do not allow arbitrary calls to non-secure(http only) domains. It was a feature introduced with iOS 9 in order to push developers onto more secured connections.
As per writing of this(mid 2017), there is workaround. You should open
{Your-project}/ios/{Your-project}/Info.plist
and set proper values for the domain you are targeting(docs).
Following example will disable ATS and allow HTTP call to somedomain.com:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
In your situation, I believe you are looking for the Info.plist file in the wrong place. It is not part of the node modules, instead look at the ios path specified above.
Unfortunately Expo doesn't allow you to modify the App Transport Security Settings but may bake in a configuration option. Here's a Github thread.
You can eject from Expo but only do this if you are 100% sure.
This will give you a project very similar to one created by react-native init
This features an ios and android directory, navigating to ios/YourProject/ will reveal Info.plist.
How much of a struggle would it be to install an SSL certificate on your server? It may be more beneficial to do this and you can use a free service like letsencrypt.

Json error in SAP oData service iOS application

I created sample app using SAP Cloud platform, it also generated Proxy classes with backend url "http://staging.*****.com/OData/sapiOS.svc/". When I running the app it didn't display the details and shows an error:
" JsonError: Expected token start character, found '<'." JsonError.
You can ignore all app transport security restrictions with a single key add these to the Info.plist open as Source Code:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

iOS9 App Transport Security

I am attempting to send a http:// request however, ATS keeps blocking my request. I have turned on Allow Arbitrary Loads in the Info.plist and it still gives me the same error:
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
You can add exceptions for specific domains in your Info.plist
You can bypass this by adding this key to your info.plist of the project
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Your dictionary App Transport Security Settings should be named NSAppTransportSecurity. And there should be only one thing in there which is NSAllowsArbitraryLoads boolean. Something like this.

iOS9 does not load insecure resources from a secure page

Not able to load the insecure resources in secure page in iOS9 everything working fine before iOS9.
Tried with NSThirdPartyExceptionAllowsInsecureHTTPLoads but no luck.
Trying the same in webview
iOS 9 introduced the App Transport Security. This mean that any connection made of https should be TLS1.2 or higher.
You can turn ATS off for legacy system add NSAppTransportSecurity to you info.plist a dictionary and then add the key NSAllowsArbitraryLoads with bool value YES
You can try to add the following to your Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
You have to add an entry into plist. just like in below image.

iOS 9 ... Are WebView(s) exempt from the App Transport Security Exceptions (ATS) rules that block insecure HTTP hosts?

In iOS 9, Apple is blocking insecure HTTP connections for apps, unless specific hosts are whitelisted.
http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/
Are WebView(s) exempt from these rules for obvious reasons, or are we still expected to whitelist hosts that a browser opens... including all links from a given page?
I wasn't sure if this was our responsibility or if that was exempt.
SFSafariViewController can show HTTP without the NSAppTransportSecurity key.
UIWebView and WKWebView require the NSAppTransportSecurity key mentioned above to display HTTP pages.
I have inserted the following in my apps .plist per the Apple Guidance:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections - with and without SSL (DANGEROUS)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
and when I try to load my webView (from an HTTPS server no less), I get the following error and it doesn't load.
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
So I it looks like not only are they not exempt, they don't work even if you make the correct addition to the .plist.
This question was originally about iOS 9; however, according to Apple's documentation:
Starting in iOS 10.0 and later, the following subkeys are supported:
NSAllowsArbitraryLoadsInWebContent
...
Use NSAllowsArbitraryLoadsInWebContent so that you do not need to white list each page a WebView may load.
Keep NSAllowsArbitraryLoads to maintain backward compatibility with iOS 9 and enable the new setting in your Xcode 8 project Info.plist here:
If your app (a third-party web browser, for instance) needs to load arbitrary content, Apple provides a way to disable ATS altogether, but I suspect it’s wise for you to use this capability sparingly:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

Resources