Skip to content

Instantly share code, notes, and snippets.

@XVXVXXX
Created December 3, 2015 09:45
Show Gist options
  • Save XVXVXXX/3d831190b782e690a3ce to your computer and use it in GitHub Desktop.
Save XVXVXXX/3d831190b782e690a3ce to your computer and use it in GitHub Desktop.
iOS-获取相册最后一张照片
#pragma mark 获取相册最后一张照片
- (void)p_getLastestPhoto
{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
__block UIImage *imagelast;
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Within the group enumeration block, filter to enumerate just photos.
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
// Chooses the photo at the last index
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];
imagelast = latestPhoto;
// Stop the enumerations
*stop = YES; *innerStop = YES;
self.screenshotImage = imagelast;
// Do something interesting with the AV asset.
//[self sendTweet:latestPhoto];
}
}];
} failureBlock: ^(NSError *error) {
// Typically you should handle an error more gracefully than this.
MGJLog(@"SSC获取截图失败");
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment