ios - Having separate cookie storage for two UIWebView? -
background
developing simple ipad application allow user browse same website different logins @ same time. therefore have 2 uiwebview
, should have different cookie storage user can login 1 account on first uiwebview
, account on second uiwebview
.
what have tried?
think solution implement different cookie storages in 2 uiwebview
have.
sasmito adibowo wrote article implementing own cookie storage provide details on how use custom cookie storage webview
on mac.
done modify nsurlrequest webview
going send, adding cookie headers it, , intercept response webview
, extract cookies response header , save our own cookie storage.
technically, done implementing these 2 delegate methods:
- (void)webview:(webview *)sender resource:(id)identifier didreceiveresponse:(nsurlresponse *)response fromdatasource:(webdatasource *)datasource - (nsurlrequest *)webview:(webview *)sender resource:(id)identifier willsendrequest:(nsurlrequest *)request redirectresponse:(nsurlresponse *)redirectresponse fromdatasource:(webdatasource *)datasource
although undocumented, uiwebview
did support 1 of method above different method name:
- (nsurlrequest *)uiwebview:(uiwebview *)sender resource:(id)identifier willsendrequest:(nsurlrequest *)request redirectresponse:(nsurlresponse *)redirectresponse fromdatasource:(id)datasource
however, uiwebview
don't have equivalent delegate method webview:resource:didreceiveresponse:fromdatasource:
, hence cannot extract cookies response headers.
the question
there way have uiwebview
use custom cookie storage, 2 uiwebview
can have own cookie storage?
thanks!
have tried getting cookies associated particular webview (and holding onto them) in webviewdidstartload:
nshttpcookie *cookie; nshttpcookiestorage *cookiejar = [nshttpcookiestorage sharedhttpcookiestorage]; (cookie in [cookiejar cookies]) { [self.cookies addobject:cookie]; }
and storing these cookies right after (retrieve values , keys self.cookies):
nsmutabledictionary *cookiedict = [nsmutabledictionary dictionary]; [cookiedict setobject:@"value1" forkey:nshttpcookiename]; [cookiedict setobject:@"value2" forkey:nshttpcookievalue]; [cookiedict setobject:@"value3" forkey:nshttpcookiedomain]; ...etc.. nshttpcookie *cookie = [nshttpcookie cookiewithproperties:cookiedict]; [[nshttpcookiestorage sharedhttpcookiestorage] setcookie:cookie];
you'll need see in viewdidload:
[[nshttpcookiestorage sharedhttpcookiestorage] setcookieacceptpolicy:nshttpcookieacceptpolicyalways];
Comments
Post a Comment