Opening ViewController when click on button in UIWebView swift

后端 未结 2 1253
日久生厌
日久生厌 2021-02-06 17:34

I Have an app which has UIWebView and the Webview contains simple Button

and here\'s my WebViewController :

import UIKit

class testV         


        
相关标签:
2条回答
  • 2021-02-06 17:52

    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;
    }
    
    0 讨论(0)
  • 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
        }
    
    0 讨论(0)
提交回复
热议问题