繁体   English   中英

iOS 8照片框架:获取特定的相册列表

[英]iOS 8 Photos framework: Get a specific list of albums

除了我自己相册中的照片之外,我正在尝试全部获取所有照片。 我尝试使用此答案中的方法获取所有照片。 ios-获取相册列表的简单示例? 但我找不到过滤自己的专辑的选项。

我使用下面的代码...我可以获取除我自己的相册以外的相册,但是如何获取除我自己相册中的照片以外的所有照片的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];
                }
    }];
}];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM