Created
December 3, 2015 09:45
-
-
Save XVXVXXX/3d831190b782e690a3ce to your computer and use it in GitHub Desktop.
iOS-获取相册最后一张照片
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
#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