thieumao

WebView

Apr 25th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.79 KB | None | 0 0
  1. import UIKit
  2.  
  3. class WebviewViewController: UIViewController {
  4.  
  5.     @IBOutlet weak var webView: UIWebView!
  6.     private var requestUrl:String? = "https://easyiot-cloud.com/"
  7.    
  8.     override func viewDidLoad() {
  9.         super.viewDidLoad()
  10.         webView.delegate = self
  11.         if let url = requestUrl {
  12.             if let urlRequest = URL(string: url) {
  13.                 webView.loadRequest(URLRequest(url: urlRequest))
  14.             }
  15.         }
  16.     }
  17.    
  18.     func shouldHandleRequest(_ request: URLRequest) -> Bool {
  19.         return true
  20.     }
  21.  
  22. }
  23.  
  24. extension WebviewViewController: UIWebViewDelegate {
  25.     func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
  26.         return shouldHandleRequest(request)
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment