1

I'm working on a mobile app that will only display a web site. It's not a big project, it's just to show how the web site that i aim could be renderer in an app like this.

I've manage to do it in Android with the WebView object, but i had to deal with ssl certificats, and Timeout exception.

Now that this app work, i have to do the same on IOS ... but i don't know anything in the Apple brand. I've "studying" the subject and managed to display a website un my application, but now i have the same issue as for android: deal with ssl certificat (And maybe TimeoutException).

I followed several question here, especially this one but the app load the page for ever. (It work with https://www.google.com/) The only messages i get are this one :

2018-04-09 17:32:13.252805+0200 myproject[64445:1704413] [MC] Lazy loading NSBundle MobileCoreServices.framework

2018-04-09 17:32:13.254114+0200 myproject[64445:1704413] [MC] Loaded MobileCoreServices.framework

I'm using Xcode, and it seems to be the version 4.0.3 of Swift

Here is my code:

import UIKit
import WebKit

class ViewController: UIViewController, WKUIDelegate {

@IBOutlet var webView: WKWebView!

override func loadView() {
    let webConfiguration = WKWebViewConfiguration()
    
    webView = WKWebView(frame: .zero, configuration:webConfiguration)
    webView.uiDelegate=self
    view=webView
}

func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
    let cred = URLCredential(trust: challenge.protectionSpace.serverTrust!)
    completionHandler(.useCredential, cred)
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    
    print("Chargement des données ...")
    let url = URL(string:"https://myWebSite.fr/")
    //let url = URL(string:"https://www.google.com")
    
    let request = URLRequest(url: url!)
    webView.load(request)
    
}

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

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
    self.view.endEditing(true)
}

}

Hope it will not be considered as a duplicate of another question i missed. Thanks in advance.

Community
  • 1
  • 1
Usapii
  • 11
  • 8

0 Answers0