Skip to content

Instantly share code, notes, and snippets.

@kiritmodi2702
Created May 27, 2016 06:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiritmodi2702/b8a674bb66803c1397cab55030ae2c54 to your computer and use it in GitHub Desktop.
Save kiritmodi2702/b8a674bb66803c1397cab55030ae2c54 to your computer and use it in GitHub Desktop.
WKWebView in Swift.
import UIKit
import WebKit
class ViewController: UIViewController , WKNavigationDelegate{
var webView : WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// loading URL :
let myBlog = "https://iosdevcenters.blogspot.com/"
let url = NSURL(string: myBlog)
let request = NSURLRequest(URL: url!)
// init and load request in webview.
webView = WKWebView(frame: self.view.frame)
webView.navigationDelegate = self
webView.loadRequest(request)
self.view.addSubview(webView)
self.view.sendSubviewToBack(webView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//MARK:- WKNavigationDelegate
func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
print(error.localizedDescription)
}
func webView(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
print("Strat to load")
}
func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
print("finish to load")
}
}
@kiritmodi2702
Copy link
Author

@iDontEvenDevBro
Copy link

Any recent updates on this for xcode 8?

@sai529
Copy link

sai529 commented Nov 29, 2017

i got below error while
let myUrl = "https://www.google.com/"
let url = NSURL(String:myUrl) . //Argument labels '(String:)' do not match any available overloads
let request = NSURLRequest(URL: url)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment