Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. class ViewController: UIViewController, WKUIDelegate {
  2.  
  3. var webView: WKWebView!
  4.  
  5. override func loadView() {
  6. let webConfiguration = WKWebViewConfiguration()
  7. webView = WKWebView(frame: .zero, configuration: webConfiguration)
  8. webView.uiDelegate = self
  9. view = webView
  10. }
  11.  
  12. // #1 variant
  13. func webView(webView: WKWebView, willSendRequestForAuthenticationChallenge challenge:
  14. URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
  15. let user = "user"
  16. let password = "pass"
  17. let credential = URLCredential(user: user, password: password, persistence: URLCredential.Persistence.forSession)
  18. challenge.sender?.use(credential, for: challenge)
  19. }
  20.  
  21. // #2 variant
  22. func webView(webView: WKWebView, didReceiveAuthenticationChallenge challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
  23.  
  24. let user = "user"
  25. let password = "pass"
  26. let credential = URLCredential(user: user, password: password, persistence: URLCredential.Persistence.forSession)
  27. challenge.sender?.use(credential, for: challenge)
  28.  
  29. }
  30.  
  31. override func viewDidLoad() {
  32. super.viewDidLoad()
  33.  
  34. let myURL = URL(string: "https://myurl.com")
  35. let myRequest = URLRequest(url: myURL!)
  36. webView.load(myRequest)
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement