Created
April 29, 2020 03:28
-
-
Save BoogieMonster1O1/6a38db34897ca463b2855d20444345c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// Test0 | |
// | |
import UIKit | |
import WebKit | |
class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate, UIWebViewDelegate { | |
var webView: WKWebView! | |
override func loadView() { | |
let preferences = WKPreferences() | |
preferences.javaScriptEnabled = true | |
preferences.javaScriptCanOpenWindowsAutomatically = true | |
let webConfiguration = WKWebViewConfiguration() | |
webConfiguration.preferences = preferences | |
webView = WKWebView(frame: .zero, configuration: webConfiguration) | |
let userAgentValue = "random-user-agent-value" | |
webView.customUserAgent = userAgentValue | |
webView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | |
webView.uiDelegate = self | |
view = webView | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let myURL = URL(string: "https://www.papertoys.com") | |
let myRequest = URLRequest(url: myURL!) | |
webView.load(myRequest) | |
webView.navigationDelegate = self | |
} | |
override func viewWillDisappear(_ animated: Bool) { | |
let dataStore = WKWebsiteDataStore.default() | |
dataStore.httpCookieStore.getAllCookies({ (cookies) in | |
print(cookies) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment