webView on iOS is not accessing some websites

Asked

Viewed 213 times

2

I’m trying to develop an iOS app using the objective-c language. But I have a domain .metaweb that I need it to access is not loading. I noticed that some sites like for example facebook, globoesportis, espn it also does not carry, however google, Linkedin, yahoo it accesses. The code I’m using is:

NSURL *url = [NSURL URLWithString:@"http://www.metaweb.com.br"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];

Do you have any idea what might be going on?

  • What version of iOS are you using?

2 answers

2


iOS 9 by default blocks HTTP connections. To enable them, open the Info.plist file in text mode (right click, Open As/Source Code) and add the following configuration inside the dictionary, at the root:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict> 
  • 1

    Although it works the recommended is to add a list of domains that your app needs to access using Nsexceptiondomains

0

For a solution on Swift, I recommend using Csafariwebkit

In your file

import CSafariWebKit

And wherever you want to call Webview

let vc = SafariViewController(url: url, barTintColor: nil, tintColor: nil)
vc.presentSafari(fromViewController: self, whenDidFinish: nil)

Use the colors of your app for a better experience.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.