Opening Viewcontroller When Click On Button In Uiwebview Swift
I Have an app which has UIWebView and the Webview contains simple Button and here's my WebViewController : import UIKit class testViewController: UIViewController { internal
Solution 1:
You can assign a scheme in the js action:
window.location = yourscheme://<scheme_content>
and in swift layer you can use the callback:
funcwebView(webView: UIWebView!, shouldStartLoadWithRequestrequest: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool {
if (request.URL.scheme =="yourscheme") {
// Your code
}
returntrue;
}
Solution 2:
Yes you can do that like this :
funcwebView(webView: UIWebView, shouldStartLoadWithRequestrequest: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if (navigationType ==UIWebViewNavigationType.FormSubmitted) {
letVC=self.storyboard?.instantiateViewControllerWithIdentifier("myViewControllerName") as? myViewControllerName
let navigationController =UINavigationController(rootViewController: VC!)
self.navigationController?.presentViewController(navigationController, animated: true, completion:nil)
}
returntrue
}
Post a Comment for "Opening Viewcontroller When Click On Button In Uiwebview Swift"