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 ?
答案 0 :(得分:0)
您可以使用WKScriptMessage
和javascript对viewController进行回调并提取本机代码。
在你的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()
}
}
}
在您的HTML文件中:
<!-- 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>