我正在尝试获取除我自己相册中的照片之外的所有照片。 我尝试使用此答案中的方法获取所有照片。 ios - Simple example to get list of photo albums? 但我找不到过滤我自己相册的选项。
我使用如下代码...我可以获得除我自己的相册之外的相册,但是我如何才能获得除我自己相册中的照片以外的所有照片的 PHFetchResult?
谢谢。
PHFetchOptions *albumsFetchOption = [[PHFetchOptions alloc]init];
NSString *string = @"MyCam";
albumsFetchOption.predicate = [NSPredicate predicateWithFormat:@"title != %@",string];
PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:albumsFetchOption];
最佳答案
最后,我使用 NSArray 而不是 PHFetchResult...
//获取全部
PHFetchOptions *allPhotosfetchOption = [[PHFetchOptions alloc]init];
allPhotosfetchOption.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
allPhotosfetchOption.predicate = [NSPredicate predicateWithFormat:@"mediaType == 1"];
__block NSMutableArray *allAssetArray = [NSMutableArray new];
PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosfetchOption];
[result enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
[allAssetArray addObject:asset];
}];
//MyCam Album
NSString *string = @"MyCam";
PHFetchOptions *albumFetchOption = [[PHFetchOptions alloc]init];
albumFetchOption.predicate = [NSPredicate predicateWithFormat:@"title == %@",string];
PHFetchResult *albumResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:albumFetchOption];
[albumResult enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL *stop) {
PHFetchResult *loftAssetResult = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
[loftAssetResult enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
if ([allAssetArray containsObject:asset]) {
[allAssetArray removeObject:asset];
}
}];
}];
关于iOS 8 照片框架 : Get a specific list of albums,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27056381/