Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ViewController: UIViewController, WKUIDelegate {
- var webView: WKWebView!
- override func loadView() {
- let webConfiguration = WKWebViewConfiguration()
- webView = WKWebView(frame: .zero, configuration: webConfiguration)
- webView.uiDelegate = self
- view = webView
- }
- // #1 variant
- func webView(webView: WKWebView, willSendRequestForAuthenticationChallenge challenge:
- URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
- let user = "user"
- let password = "pass"
- let credential = URLCredential(user: user, password: password, persistence: URLCredential.Persistence.forSession)
- challenge.sender?.use(credential, for: challenge)
- }
- // #2 variant
- func webView(webView: WKWebView, didReceiveAuthenticationChallenge challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
- let user = "user"
- let password = "pass"
- let credential = URLCredential(user: user, password: password, persistence: URLCredential.Persistence.forSession)
- challenge.sender?.use(credential, for: challenge)
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- let myURL = URL(string: "https://myurl.com")
- let myRequest = URLRequest(url: myURL!)
- webView.load(myRequest)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement