首页 > 解决方案 > 如何清除 OAuthSwift 库中的 cookie(OAuth2.0)

问题描述

我在我的应用程序中使用 OAuthSwift Auth2.0 库,我们正在尝试使用以下代码在按下“注销”按钮时清除浏览器中的 cookie 详细信息,但脚本不会从内部浏览器中删除会话 cookie。我无法从内部浏览器中清除 cookie。

//Calling the URl
     oauthswift.authorizeURLHandler = SafariURLHandler(viewController: self, oauthSwift: oauthswift)
    SafariURLHandler(viewController: self,oauthSwift:oauthswift)
// Remove the cookies
URLCache.shared.removeAllCachedResponses()
        if let cookies = HTTPCookieStorage.shared.cookies{
            for cookie in cookies {
                HTTPCookieStorage.shared.deleteCookie(cookie)
            }
        }
        let storage = HTTPCookieStorage.shared
        if let cookies = storage.cookies {
            for cookie in cookies {
                storage.deleteCookie(cookie)
            }
        }
        let dataTypes = Set([WKWebsiteDataTypeCookies,
         WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeSessionStorage,
         WKWebsiteDataTypeWebSQLDatabases, WKWebsiteDataTypeIndexedDBDatabases])
         WKWebsiteDataStore.default().removeData(ofTypes: dataTypes, modifiedSince: NSDate.distantPast, completionHandler: {})

        navigationController?.popToRootViewController(animated: true)
    }

有人可以帮忙吗?

标签: iosswiftoauth-2.0

解决方案


推荐阅读