Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save propstm/4400873 to your computer and use it in GitHub Desktop.

Select an option

Save propstm/4400873 to your computer and use it in GitHub Desktop.
Method that takes an ALAssetLibrary group name as a string and returns the last ALAsset entered for that group.
-getLastAssetFromCustomFolderWithName:(NSString*)folderName{
if(assets == nil){
//Used to collect our applicable assets
assets = [[NSMutableArray alloc] init];
}
if(library == nil){
//
//The lifetimes of objects you get back from a library instance are tied to the lifetime of the library instance.
//source: http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html
//
library = [[ALAssetsLibrary alloc] init];
}
NSAssert(library, @"Unable to open ALAssetsLibrary");
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:^(ALAssetsGroup *group, BOOL *stop){
if([[group valueForProperty:@"ALAssetsGroupPropertyName"] isEqualToString:folderName]){
NSLog(@"GROUP NAME: %@", [group valueForProperty:@"ALAssetsGroupPropertyName"]);
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset) {
NSLog(@"ASSET, %@", asset);
[assets addObject:asset];
}
}];
dispatch_async(dispatch_get_main_queue(), ^{
for(ALAsset *asset in assets){
NSLog(@"ASSET CREATION DATE: %@", [asset valueForProperty:@"ALAssetPropertyDate"]);
}
NSLog(@"ASSETS COUNT: %i", [assets count]);
if([assets count] > 0){
//HAVE ASSETS, GO!!
//Last asset is most recent (just saved)!
NSLog(@"LAST ASSET: %@", [assets objectAtIndex:[assets count]-1]);
[self doSomethingWithAsset:[assets objectAtIndex:[assets count]-1]];
}
});
}
}
failureBlock:^(NSError *err){
NSLog(@"err=%@", err);
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment