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?
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];
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With