I making app in Swift 3 enter image description hereFirstly login on my app after redirect web view.If i click logout button in web view page I want to redirect back my App.How can i do it ?
Asked
Active
Viewed 324 times
0
-
What have you tried — how are you displaying this webview? – Chris Droukas Mar 22 '17 at 18:43
-
with loadRequest method – Burak Şentürk Mar 22 '17 at 18:46
-
Sure, but you have a view controller that presents a webview (or something)? – Chris Droukas Mar 22 '17 at 18:47
-
of course WebViewController my present webview i input username and password my app after login on website – Burak Şentürk Mar 22 '17 at 18:49
-
1In that case, use `UIWebViewDelegate` to invoke native (Swift or Obj-C) functions/methods from your webview. http://stackoverflow.com/a/15541607/1313761 – Chris Droukas Mar 22 '17 at 18:57
1 Answers
0
You can use a WKScriptMessage
and javascript to make a callback to your viewController and exicute native code.
In your viewController:
//MARK: WKScriptMessageHandler (callback from js in HTML file)
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage){
if message.name == "callbackHandler" {
print(message.body)
//My function
if (message.body as AnyObject).contains("myFunctionName"){
self.playVideo()
}
}
}
In your HTML file:
<!-- JS for Native Application Callbacks -->
<script type="text/javascript">
function callNativeApp () {
//iOS
try {
window.webkit.messageHandlers.callbackHandler.postMessage("myFunctionName");
} catch(err) {
console.log('The native context does not exist yet');
}
}
</script>

rmp
- 3,503
- 1
- 17
- 26