ios - How to only allow certain URLs in app -
is there way allow app load urls? thinking there exception domains in app transport security settings, except not allowing arbitrary loads url, rather allow urls , block others, whether or not https/http. thanks
you can use in appdelegate:
optional func application(_ app: uiapplication, openurl url: nsurl, options options: [string : anyobject]) -> bool { //return true or false depending on if want //this application open url. }
in comments mention using in single uiwebview. in case can following:
func webview(webview: uiwebview, shouldstartloadwithrequest request: nsurlrequest, navigationtype: uiwebviewnavigationtype) -> bool { let url = request.url return handlerequest(url) } @available(ios 8.0, *) func webview(webview: wkwebview, decidepolicyfornavigationaction navigationaction: wknavigationaction, decisionhandler: (wknavigationactionpolicy) -> void) { let request = navigationaction.request; let url = request.url if(handlerequest(url)) { decisionhandler(wknavigationactionpolicy.allow) } else { decisionhandler(wknavigationactionpolicy.cancel) } }
that bit of code handles both uiwebview , wkwebview.
Comments
Post a Comment