objetivo c enviar cookies a uiwebview
Necesito enviar cookies para iniciar sesión en un UIWebView, pero cuando cargo la página web no se han enviado las cookies.
Mi código es:
CorreoViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.title =AMLocalizedString(@"Correo", @"");
NSURL *url=[NSURL URLWithString:@"https://cuentas.uv.es/cgi-bin/p/user/Usuario"];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
NSArray * cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
NSDictionary * headers = [NSHTTPCookie requestHeaderFieldsWithCookies: cookies];
[request setHTTPMethod:@"Post"];
[request setHTTPShouldHandleCookies:YES];
[request setAllHTTPHeaderFields:headers];
NSLog(@"Request: %@", [[request allHTTPHeaderFields] objectForKey:@"cookie"]);
[self.webView loadRequest:request];
// Do any additional setup after loading the view.
}
Y las cookies que tengo en mi almacenamiento de cookies son:
COOKIE 0: Versión NSHTTPCookie: 0 nombre: "PAPIAuthNcook" valor: "nBNqHJSdjgo1aBw0uGh3AXzElIHCxA% 2FDbnipSHWZbU5Eh1cJfUr18GEP9zxB% 2BL% 2FZGPBAKQu6oF2l% 0AzIMt7ywiSECLBuOHJnvS7y6rVim2HfE% 3D% 0A" expiresDate: (null) creado: 16/01/2014 15:05:41 +0000 (4,11578 e + 08) sessionOnly: TRUE domain: "cuentas.uv.es" ruta: "/" isSecure: FALSE
COOKIE 1: NSHTTPCookie versión: 0 nombre: "PAPIslist" valor: "17201128679244079 |https://uvapp.uv.es/"expiresDate: (null) created: 2014-01-16 15:05:41 +0000 (4.11578e + 08) sessionOnly: TRUE domain:" cuentas.uv.es "path:" / "isSecure: FALSE
2 de la galleta: Versión NSHTTPCookie: 0 nombre: "PAPIAuthNcook" valor: "nBNqHJSdjgo1aBw0uGh3AXzElIHCxA% 2FDbnipSHWZbU5Eh1cJfUr18GEP9zxB% 2BL% 2FZGPBAKQu6oF2l% 0AzIMt7ywiSECLBuOHJnvS7y6rVim2HfE% 3D% 0A" expiresDate: (null) creado: 16/01/2014 15:05:41 +0000 (4,11578 e + 08) sessionOnly: TRUE domain: "as.uv.es" path: "/" isSecure: FALSE
COOKIE 3: NSHTTPCookie versión: 0 nombre: valor "PAPIslist": "17201128679244079 |https://uvapp.uv.es/"expiresDate: (null) created: 2014-01-16 15:05:41 +0000 (4.11578e + 08) sessionOnly: TRUE domain:" as.uv.es "path:" / "isSecure: FALSE
AppDelegate.m
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
[[NSHTTPCookieStorage sharedHTTPCookieStorage]setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
}
Gracias de antemano.