【发布时间】:2014-07-05 07:40:02
【问题描述】:
我正在尝试访问照片库中拍摄的最后一张照片,一切正常,除非照片库没有照片,我的应用程序崩溃了!如何找到停止崩溃的解决方案?这是我的代码:
-(void)importLastImage {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// 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 enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:([group numberOfAssets]-1)]
options:0
usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
latestPhoto = [UIImage imageWithCGImage:[representation fullResolutionImage]];
}else {
}
}];
}
failureBlock: ^(NSError *error) {
// Typically you should handle an error more gracefully than this.
NSLog(@"No groups");
}];
}
【问题讨论】:
标签: ios objective-c alassetslibrary