开发者

How can I remove cookies stored by WebView in Cocoa application?

My Cocoa app uses WebView to open pages that uses cookies. For testing purposes I want to remove those cookies. How can I do this (programmatically or manually) 开发者_如何学运维?


If you wanted to do it programmatically, you can use NSHTTPCookieStorage

You'll need cookiesForURL: and deleteCookie:. Something a little like this (untested):

NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];

for (NSHTTPCookie *cookie in [cookieJar cookiesForURL:@"http://myserver.com"]) 
{
  [cookieJar deleteCookie:cookie];
}


Originally, cookies were shared between apps on Mac OS X. So you could use the Safari preferences to remove all cookies.

However, as of OS X 10.11, that potential security hole has been closed, and all apps have their own cookie store. (and even before that, sandboxed apps had their own cookie store too)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜