Code below is very simple. I use WKWebView to login to my Microsoft account.
class MSAuthenticationViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {
@IBOutlet var webView: WKWebView!
@IBOutlet var DoneBonnon: UIBarButtonItem!
@IBOutlet var RefreshButton: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
self.webView.getCookies() { cookies in // for debug
print("# of cookies", cookies.count)
}
let websiteDataStore = WKWebsiteDataStore.default()
let configuration = WKWebViewConfiguration()
configuration.websiteDataStore = websiteDataStore
webView = WKWebView(frame: view.frame, configuration: configuration)
webView.uiDelegate = self
webView.navigationDelegate = self
let url = URL(string: "https://login.microsoftonline.com")!
let request = URLRequest(url: url)
webView.load(request)
view = webView
}
}
I close the controller by swiping it down. When I open it again, I have to re-login despite the number of cookies didn't change. Basically this means, that closing the controller logs me out.
My aim is to stay logged in, meaning when I open the controller again, that I'm still logged in.
What do I miss?