Skip to content Skip to sidebar Skip to footer

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:

func webView(webView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool {
    if (request.URL.scheme == "yourscheme") {
        // Your code
    }
    return true;
}

Solution 2:

Yes you can do that like this :

func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        
        if (navigationType == UIWebViewNavigationType.FormSubmitted) {
            let VC = self.storyboard?.instantiateViewControllerWithIdentifier("myViewControllerName") as? myViewControllerName

            let navigationController = UINavigationController(rootViewController: VC!)
            self.navigationController?.presentViewController(navigationController, animated: true, completion:nil)

    
        }
        return true
    }

Post a Comment for "Opening ViewController When Click On Button In UIWebView Swift"