Created
October 7, 2011 22:19
-
-
Save cschep/1271475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load Albums into assetGroups | |
dispatch_async(dispatch_get_main_queue(), ^ | |
{ | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
// Group enumerator Block | |
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) | |
{ | |
if (group == nil) | |
{ | |
return; | |
} | |
[self.assetGroups addObject:group]; | |
// Keep this line! w/o it the asset count is broken for some reason. Makes no sense | |
NSLog(@"count: %d", [group numberOfAssets]); | |
// Reload albums | |
[self performSelectorOnMainThread:@selector(reloadTableView) withObject:nil waitUntilDone:YES]; | |
}; | |
// Group Enumerator Failure Block | |
void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) { | |
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"Album Error: %@", [error description]] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; | |
[alert show]; | |
[alert release]; | |
NSLog(@"A problem occured %@", [error description]); | |
}; | |
// Enumerate Albums | |
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; | |
[library enumerateGroupsWithTypes:ALAssetsGroupAll | |
usingBlock:assetGroupEnumerator | |
failureBlock:assetGroupEnumberatorFailure]; | |
[library release]; | |
[pool release]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment