Skip to content

Instantly share code, notes, and snippets.

@markdarling
Created March 14, 2012 16:42
Show Gist options
  • Save markdarling/2037771 to your computer and use it in GitHub Desktop.
Save markdarling/2037771 to your computer and use it in GitHub Desktop.
Get Last Photo from Camera Roll
- (void)getLatestPhoto {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:[group numberOfAssets]-1] options:0 usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullResolutionImage]];
// Got the lastestPhoto
}
}];
}
failureBlock: ^(NSError *error) {
NSLog(@"Error");
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment