Skip to content

Instantly share code, notes, and snippets.

@aaronpearce
Created February 15, 2012 22:20
Show Gist options
  • Save aaronpearce/1839441 to your computer and use it in GitHub Desktop.
Save aaronpearce/1839441 to your computer and use it in GitHub Desktop.
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0ul), ^{
// Do a taks in the background
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[[storage cookies] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[storage deleteCookie:obj];
if(stop) {
NSArray *cookies = [NSKeyedUnarchiver unarchiveObjectWithData:[[self.array objectAtIndex:indexPath.row] objectAtIndex:1]];
[cookies enumerateObjectsUsingBlock:^(id obj2, NSUInteger idx, BOOL *stop2) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:obj2];
if(stop2) {
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"getFolders" object:nil];
[[NSUserDefaults standardUserDefaults] setValue:[[self.array objectAtIndex:indexPath.row] objectAtIndex:0] forKey:@"currentUser"];
[[NSUserDefaults standardUserDefaults] synchronize];
[SVProgressHUD dismissWithSuccess:@"Switched!"];
[self closeView];
});
}
}];
}
}];
// Hide the HUD in the main tread
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment