Upload website in UIWebView Swift 3

0

Good morning staff

I can load a web page quietly into a UIWebView with the following Swift code:

import UIKit

class ConteudoOnlineViewController: UIViewController {
@IBOutlet weak var pagina: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()

    pagina.delegate = self as? UIWebViewDelegate
    if let url = URL(string: "http://www.meusite.com.br/login.aspx") {
        let request = URLRequest(url: url)
        pagina.loadRequest(request)
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
    }
}

But my site has a login page and I created a validation to access directly by passing a token, it happens that now I can not load this page in UIWebView, it simply does not appear anything. Could someone give me an idea of what I should do ??

import UIKit

class ConteudoOnlineViewController: UIViewController {
@IBOutlet weak var pagina: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()

    pagina.delegate = self as? UIWebViewDelegate
    if let url = URL(string: "http://www.meusite.com.br/login.aspx?token=6D5C6A4BF468D43ABD521A3C9D3469C3​") {
        let request = URLRequest(url: url)
        pagina.loadRequest(request)
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
    }
}
    
asked by anonymous 16.08.2017 / 14:39

1 answer

0

iOS has a security layer called App Transport Security (ATS) that by default blocks unsafe (HTTP) connections. Ideally, deploy the secure connection on the server side, as insecure connections can be blocked completely in some future version of iOS. If this is not possible, you can disable these restrictions through the project's info.plist file. I suggest reading the documentation at portal by Apple. In your case, probably the required configuration is something like:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>meusite.com.br</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>
    
16.08.2017 / 15:12