【发布时间】:2022-01-06 21:50:01
【问题描述】:
我制作了登录 SFSafariViewController 的应用程序。登录时效果很好。但是在我注销后,如果我再次尝试登录,我已经登录了。这是因为我的自动登录信息存储在 SFSafariViewController 中。我试图删除缓存和cookie,但它不起作用。 :(
这是我的登录代码。
func requestCode() {
let scope = "user"
let urlString = "https://github.com/login/oauth/authorize?client_id=\(clientId)&scope=\(scope)"
guard let url = URL(string: urlString) else {
return
}
URLCache.shared.removeAllCachedResponses()
if let cookies = HTTPCookieStorage.shared.cookies {
for cookie in cookies {
HTTPCookieStorage.shared.deleteCookie(cookie)
}
}
let safariViewController = SFSafariViewController(url: url)
safariViewController.delegate = self
safariViewController.modalPresentationStyle = .automatic
if let topViewController = UIApplication.shared.connectedScenes.compactMap({ $0 as? UIWindowScene }).flatMap({ $0.windows }).first(where: { $0.isKeyWindow }) {
topViewController.rootViewController?.present(safariViewController, animated: true, completion: nil)
}
}
【问题讨论】:
标签: swift ios15 sfsafariviewcontroller