Cómo dejar que la session de UIWebView nunca caduque

Estoy intentando save la session en UIWebView siguiente manera como se sugiere en este enlace:

 - (NSURLRequest*)addCookies:(NSArray *)cookies forRequest:(NSURLRequest *)request { NSMutableURLRequest *mutableRequest = [request mutableCopy]; if ([cookies count] > 0) { NSHTTPCookie *cookie; NSString *cookieHeader = nil; for (cookie in cookies) { if (!cookieHeader) { cookieHeader = [NSString stringWithFormat: @"%@=%@",[cookie name],[cookie value]]; } else { cookieHeader = [NSString stringWithFormat: @"%@; %@=%@",cookieHeader,[cookie name],[cookie value]]; } } if (cookieHeader) { [mutableRequest setValue:cookieHeader forHTTPHeaderField:@"Cookie"]; } return [mutableRequest copy]; } return nil; } 

Y en viewDidLoad :

 NSURLRequest *webRequest = [NSURLRequest requestWithURL:homeURL]; NSArray *cookies = [[NSHTTPCookieStorage shanetworkingHTTPCookieStorage] cookies]; NSMutableURLRequest *requestMut = [NSMutableURLRequest requestWithURL:webRequest.URL]; [requestMut setHTTPShouldHandleCookies:YES]; webRequest = [self addCookies:cookies forRequest:requestMut]; [_tgWebView loadRequest:webRequest]; 

Pero la aplicación vuelve a aparecer en la pantalla de inicio de session, es decir, la session no está guardando. Esta es una pregunta similar sin respuesta que acabo de encontrar.
Actualización : traté de establecer la date de caducidad de las cookies como alnetworkingedor de diez años, pero aún así el problema no es la fijación:

 + (void)loadCookies { NSArray *cookies = [NSKeyedUnarchiver unarchiveObjectWithData: [[NSUserDefaults standardUserDefaults] objectForKey: @"SAVED_COOKIES"]]; NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage shanetworkingHTTPCookieStorage]; for (NSHTTPCookie *cookie in cookies) { NSMutableDictionary *newProperties = [[NSMutableDictionary alloc]initWithDictionary:cookie.properties]; NSDate *date = [newProperties objectForKey:NSHTTPCookieExpires]; if(date == nil) [newProperties setObject:[[NSDate date] dateByAddingTimeInterval:100*12*30*60*60] forKey:NSHTTPCookieExpires]; else [newProperties setObject:[[NSDate date] dateByAddingTimeInterval:100*12*30*60*60] forKey:NSHTTPCookieExpires]; NSHTTPCookie *newCookie = [NSHTTPCookie cookieWithProperties:newProperties]; [cookieStorage setCookie: newCookie]; NSLog(@"%@",newCookie); } } 

Esa es solo una posible implementación: primero almacene las cookies

 - (void)saveCookies { NSData *cookiesData = [NSKeyedArchiver archivedDataWithRootObject: [[NSHTTPCookieStorage shanetworkingHTTPCookieStorage] cookies]]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject: cookiesData forKey: @"cookies"]; [defaults synchronize]; } 

Restaurar las cookies:

 - (void)loadCookies { NSArray *cookies = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] objectForKey: @"cookies"]]; NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage shanetworkingHTTPCookieStorage]; for (NSHTTPCookie *cookie in cookies) { [cookieStorage setCookie: cookie]; } }