In my app users login through a SafariWebViewController and I am trying to implement a logout button for my app. When the button is pressed the following code is called.
在我的应用程序中,用户通过SafariWebViewController登录,我正在尝试为我的应用程序实现注销按钮。按下按钮时,将调用以下代码。
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage
sharedHTTPCookieStorage];
for (NSHTTPCookie *cookie in [storage cookies]) {
[storage deleteCookie:cookie];
}
[[NSUserDefaults standardUserDefaults] synchronize];
The code does not properly clear the cookies and when the user tries to login the SafariWebViewController remembers their last login. I am not sure what I am doing wrong that the cookies are not clearing. Any help would be appreciated.
代码无法正确清除cookie,当用户尝试登录时,SafariWebViewController会记住他们上次登录。我不确定饼干没有清除我做错了什么。任何帮助,将不胜感激。
1 个解决方案
#1
1
NSHTTPCookieStorage
only affects UIWebView
and your own app's requests, it doesn't have any effect on WKWebView
or SFSafariViewController
, they use their own cookie handler.
NSHTTPCookieStorage仅影响UIWebView和您自己的应用程序的请求,它对WKWebView或SFSafariViewController没有任何影响,它们使用自己的cookie处理程序。
SFSafariViewController
also shares cookies with the Safari app; my guess is only the user can clear the cache themselves (for obvious security/privacy reasons).
SFSafariViewController还与Safari应用程序共享cookie;我的猜测只是用户可以自己清除缓存(出于明显的安全/隐私原因)。
Use UIWebView
or WKWebView
if you want to control the cache.
如果要控制缓存,请使用UIWebView或WKWebView。
#1
1
NSHTTPCookieStorage
only affects UIWebView
and your own app's requests, it doesn't have any effect on WKWebView
or SFSafariViewController
, they use their own cookie handler.
NSHTTPCookieStorage仅影响UIWebView和您自己的应用程序的请求,它对WKWebView或SFSafariViewController没有任何影响,它们使用自己的cookie处理程序。
SFSafariViewController
also shares cookies with the Safari app; my guess is only the user can clear the cache themselves (for obvious security/privacy reasons).
SFSafariViewController还与Safari应用程序共享cookie;我的猜测只是用户可以自己清除缓存(出于明显的安全/隐私原因)。
Use UIWebView
or WKWebView
if you want to control the cache.
如果要控制缓存,请使用UIWebView或WKWebView。