I am doing a project in login screen am posting email password in response i need to store the cookies and delete the cookies when user logged out so how can i handle this i tried with NSUrlSession and NSURLConnection but i don't know how to store the cookie and delete the cookie
NSString *noteDataString = [NSString stringWithFormat:@"user[email]=%@&user[password]=%@", userNameTF.text, passWordTF.text];
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
sessionConfiguration.HTTPShouldSetCookies = YES;
sessionConfiguration.HTTPAdditionalHeaders = @{
@"Accept": @"application/json"
};
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
NSURL *url = [NSURL URLWithString:@"http://URL/login"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPBody = [noteDataString dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPMethod = @"POST";
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary * dd = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSString * role = [dd objectForKey:@"role"];
if ([role isEqualToString:@"user"]) {
UIStoryboard * storyBD = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController * obj = [storyBD instantiateViewControllerWithIdentifier:@"tab"];
[self.navigationController pushViewController:obj animated:YES];
}
NSLog(@"%@",dd);
}];
[postDataTask resume];