ios - How to talk with main thread swift files to access main thread variables -
i experienced android dev new ios dev using swift. right have setup uiwebview , nsurlprotocol using caninitwithrequest (2 separate swift files). caninitwithrequest method works great need acccess uiwebview object in order call functions on uiwebview object.
for example. if request == google.com uiwebview.something().
in android in order talk main activity thread create interface, implement in main thread , have access on main activity class.
thanks help.
you may looking method -webview(_:shouldstartloadwithrequest:navigationtype:) in uiwebviewdelegate protocol.
by implementing interface, can have different object (e.g. object in "separate swift file") determine whether or not load nsurlrequest , run custom behavior first:
extension myobject: uiwebviewdelegate { func webview(webview: uiwebview, shouldstartloadwithrequest request: nsurlrequest, navigationtype: uiwebviewnavigationtype) -> bool { if request.url == nsurl(string: "google.com") { // custom behavior... webview.something() } // allow webview load request return true } }
Comments
Post a Comment