How is `removeCookiesSinceDate` supposed to be used?
Asked Answered
S

2

11

There is this new great method of NSHTTPCookieStorage, available since MacOS 10.10 and iOS 8.0. Guessing from the negligible number of Google hits, nobody much has noticed it yet. Not so surprising, given that it's not yet even in the Apple dev portal docs, just in header. But i still hope someone knows how to use it, because i don't :) I'm trying to use it for clearing all cookies instead of the embarrassing cookie jar iteration. So i have called it with

[NSDate dateWithTimeIntervalSince1970:0]

and BOOM, EXC_BAD_ACCESS in MemoryCookies::visitCookies. Ok UN*X epoch was too mean, probably. So i tried

[NSDate dateWithTimeIntervalSinceNow:-86400];

and BOOM again. So i continued dividing interval and found out that it indeed wants at least one cookie at least as old as the date parameter. So you would have to iterate cookies anyway to find the oldest one and then call the new shiny method. It's so ridiculously impractical that i even dare to call it a bug.

Thoughts?

Synchrotron answered 30/1, 2015 at 17:5 Comment(1)
FWIW, github.com/mluton/SafariCookies seems to work. Doesn't have a date option, but has an "all" option, and the source is available for mods. I use it with an exclusion list, so I can keep a few "good guys."Mixon
S
3

It works as expected at least since iOS 8.1, i.e. removes cookies regardless of the age and does not crash. Interestingly enough, it's still just in the headers but not in the Cocoa reference for iOS neither OSX. Probably something with NSHTTPCookieStorage being still "API in development" since iOS 2.0.

UPDATE Now also in Cocoa reference docs

Synchrotron answered 2/11, 2015 at 8:47 Comment(0)
M
4

I do think this is a bug in all versions of iOS 8. I was able to trigger this in iOS 8.3. I decided to just manually delete the cookies as follows:

NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
for (NSHTTPCookie *cookie in cookies) {
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
Mucus answered 23/6, 2016 at 22:46 Comment(0)
S
3

It works as expected at least since iOS 8.1, i.e. removes cookies regardless of the age and does not crash. Interestingly enough, it's still just in the headers but not in the Cocoa reference for iOS neither OSX. Probably something with NSHTTPCookieStorage being still "API in development" since iOS 2.0.

UPDATE Now also in Cocoa reference docs

Synchrotron answered 2/11, 2015 at 8:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.