It should be better to read the cookie and simply write the code segment here. It is easy to understand. You should put it in webviewdidfinishload and execute it
Nsarray * ncookies = [[nshttpcookiestorage sharedhttpcookiestorage] cookies]; nshttpcookie * cookie;
For (id c in ncookies)
{
If ([C iskindofclass: [nshttpcookie class]) {
Cookie = (nshttpcookie *) C;
Nslog (@ "% @: % @", Cookie. Name, Cookie. Value );}
}
Better storage of long-term data
I want to read the cookie. In order to save the cookie, I wrote
The following two methods can be used to access data of the nsmutabledictionary type. This type of data can be understood as a key-value pair, and you can easily read and modify a healthy value through the following two lines of code.
Read
NSString *cookieValue = [cookieData valueForKey:cookieName];
Set/Add
Nsmutabledictionary * jsoncookie = [[nsmutabledictionary alloc] init]; [jsoncookie setvalue: cookievalue forkey: cookiename];
// Save the data locally
-(Bool) setlocaldata :( nsstring *) datafile dataobject :( nsmutabledictionary *) dataobject {
// Set the path and save it
Nsstring * savepath = [nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes) objectatindex: 0];
Nsstring * SaveFile = [savepath stringbyappendingpathcomponent: datafile]; [nskeyedarchiver archiverootobject: dataobject tofile: SaveFile];
Return yes;
}
// Read locally stored data
-(Nsmutabledictionary *) getlocaldata :( nsstring *) datafile {
// Read data by file name
Nsstring * savepath = [nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes) objectatindex: 0];
Nsstring * SaveFile = [savepath stringbyappendingpathcomponent: datafile]; return [nskeyedunarchiver unarchiveobjectwithfile: SaveFile];
}