iOS 8 照片框架 : Get a specific list of albums

标签 ios objective-c phasset

我正在尝试获取除我自己相册中的照片之外的所有照片。 我尝试使用此答案中的方法获取所有照片。 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/

相关文章:

ios - NSDateFormatter 意外调整时间的问题

objective-c - 如何从 MacOS 的照片库中获取所有 PHAssets

ios - 如何使用 PHAsset 在 iOS 8 中获取图像或视频的 MIME 类型?

ios - 如何在 Arkit 中提供持久性?

objective-c - facebook sdk 3.1-ios 与 ios 5.1 -5 兼容吗?

ios - 编译时错误: No known instance method for selector 'setDetailItem:'

ios - 从现有 phAsset 修改元数据似乎不起作用

ios - 如何使用 SDWebImage 将 alpha 属性添加到 UIImage 集?

ios - 如何在 iOS 中同时为平移和高度设置动画

ios - 尝试从核心数据中的两个实体中删除数据