我正在使用以下代码访问所有 ALAssetsLibrary 图像,但 ALAssetsLibrary 为我提供了保存的视频缩略图图像以及来自 ALAssetsLibrary 的保存图像。如何使用代码防止这种情况,以便我只能获取保存的图像?
//Method to get all images from devices library
- (NSMutableArray*)getAllImagesFromLibrary
{
//get all images from image library
void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL) {
//Insert objects into array
[self.arrOfAllImages addObject:result];
}
};
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
}
};
//NSMutableArray allacation
NSMutableArray *arrOfAllImage = [[NSMutableArray alloc] init];
static dispatch_once_t pred = 0;
static ALAssetsLibrary *library = nil;
dispatch_once(&pred, ^{
library = [[ALAssetsLibrary alloc] init];
});
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) {
NSLog(@"Failure");
}];
return arrOfAllImage;
}