0

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 ?

1 Answers1

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