ios - Migrating UIWebView delegate to WKWebView delegate method -


i working on migrating uiwebview wkwebview. have changed delegate methods. need wkwebview delegate methods equal below uiwebview delegate method. app working fine. login session not retaining

uiwebview:      extension webviewcontroller: uiwebviewdelegate {      func webview(_ webview: uiwebview, shouldstartloadwith request: urlrequest, navigationtype: uiwebviewnavigationtype) -> bool {      guard let url = request.url else {        return true     }      guard !url.absolutestring.contains("data:application/pdf") else {         navigationitem.rightbarbuttonitem = uibarbuttonitem(barbuttonsystemitem: uibarbuttonsystemitem.action,                                                             target: self,                                                             action: #selector(share(sender:)))         return true     }      guard url.pathextension != "pdf" else {         let safarivc = sfsafariviewcontroller(url: url)         safarivc.modalpresentationstyle = .popover         present(safarivc, animated: true, completion: nil)         return false     }      guard url.islogin() == false else {         appdelegate.navigationcontroller.signout(.sessiononly)         return false     }      guard let mobilesite = url.asmobilesite() else {         return true     }      let mobileredirect = urlrequest(url: mobilesite)     webview.loadrequest(mobileredirect)     return false  }  func webviewdidstartload(_ webview: uiwebview) {     numberofdidstartloads += 1 }  func webviewdidfinishload(_ webview: uiwebview) {     numberofdidstartloads -= 1 }  func webview(_ webview: uiwebview, didfailloadwitherror error: error) {     numberofdidstartloads -= 1 } } 

and tried below code , getting session expire.

extension webviewcontroller: uiwebviewdelegate {      func webview(_ webview: wkwebview, decidepolicyfor navigationaction: wknavigationaction, decisionhandler: @escaping (_: wknavigationactionpolicy) -> void) {      guard let url = navigationaction.request.url else {         decisionhandler(.allow)         return     }      guard !url.absolutestring.contains("data:application/pdf") else {         navigationitem.rightbarbuttonitem = uibarbuttonitem(barbuttonsystemitem: uibarbuttonsystemitem.action,                                                             target: self,                                                             action: #selector(share(sender:)))         decisionhandler(.allow)         return     }      guard url.pathextension != "pdf" else {         let safarivc = sfsafariviewcontroller(url: url)         safarivc.modalpresentationstyle = .popover         present(safarivc, animated: true, completion: nil)         decisionhandler(.cancel)         return     }      guard url.islogin() == false else {         appdelegate.navigationcontroller.signout(.sessiononly)         decisionhandler(.cancel)         return     }      guard let mobilesite = url.asmobilesite() else {         decisionhandler(.allow)         return     }      let mobileredirect = urlrequest(url: mobilesite)     webview.load(mobileredirect)     decisionhandler(.cancel)     return      decisionhandler(.allow)  }      func webviewdidstartload(_ webview: uiwebview) {         numberofdidstartloads += 1     }      func webviewdidfinishload(_ webview: uiwebview) {         numberofdidstartloads -= 1     }      func webview(_ webview: uiwebview, didfailloadwitherror error: error) {         numberofdidstartloads -= 1     } } 

please me resolve issue. have made mistake in changing code uiwebview wkwebview.

i guess can use webview(_:decidepolicyfor:decisionhandler:) , block/cancel or allow requests. should work in same way.

disclaimer: haven't tested yet, i'll find time.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -