objective c - NSHTTPCookieStorage state not saved on app exit. Any definitive knowledge/documentation out there? -


struggling problem , loath implement custom cookie management system.

it appears hidden level of ios's implementation of http fails manage sessionless cookies properly. time http response sets or deletes cookie, immediate inspection of nshttpcookiestorage cookies yield expected results , indicate correct sessiononly value.

but if app quits after response updates cookies, upon relaunch sessiononly=false cookies reverted previous state , recent updates lost.

whether cookies set/deleted response header or nshttpcookiestorage setcookie: makes no difference.

some caching/syncing voodoo must going on behind scenes. time takes cookie become persistent can 5 seconds.

anyone out there has or can point definitive explanation of behavior? bug, plain , simple? or undocumented feature purpose can't comprehend?

some code can use reproduce:

- (void)applicationdidbecomeactive:(uiapplication *)application {      [[nshttpcookiestorage sharedhttpcookiestorage] setcookieacceptpolicy:nshttpcookieacceptpolicyalways];      nshttpcookie *cookie;     (cookie in [nshttpcookiestorage sharedhttpcookiestorage].cookies) {         nslog(@"%@=%@", cookie.name, cookie.value);     }      nsmutabledictionary *cookieproperties = [nsmutabledictionary dictionary];     [cookieproperties setobject:@"testcookie" forkey:nshttpcookiename];     [cookieproperties setobject:[nsstring stringwithformat:@"%f", [[nsdate date] timeintervalsince1970]] forkey:nshttpcookievalue];     [cookieproperties setobject:@"www.example.com" forkey:nshttpcookiedomain];     [cookieproperties setobject:@"www.example.com" forkey:nshttpcookieoriginurl];     [cookieproperties setobject:@"/" forkey:nshttpcookiepath];     [cookieproperties setobject:@"0" forkey:nshttpcookieversion];      // set expiration 1 month     [cookieproperties setobject:[[nsdate date] datebyaddingtimeinterval:2629743] forkey:nshttpcookieexpires];      cookie = [nshttpcookie cookiewithproperties:cookieproperties];     [[nshttpcookiestorage sharedhttpcookiestorage] setcookie:cookie];  } 

this code should output new value on every launch. instead see if quit app value unchanged.

some possibly related stack overflow questions:

iphone nshttpcookiestorage avaible on app reopen?

iphone: nshttpcookie not saved across app restarts

nshttpcookies refuse deleted

deleted nshttpcookie returns if app terminated

i think answer lies in one of posts linked in question:

i made sample project reproduce issue — , found occur when app receives sigkill signal, when debugger stopped within xcode. in experiments, unhandled exceptions, crashes, exit() , abort() don't cause nshtppcookiestorage loose data.

as looks debugging-only issue (it occurs when using debugger), closed radar filled previously.

you can test restarting phone , observing changes nshttpcookiestorage correctly persisted , reloaded.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -