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

问题描述:

我想通过除我自己的相册中的照片获取所有照片。 我尝试使用此答案中的方法获取所有照片。 ios - Simple example to get list of photo albums? 但我无法找到一个选项来过滤我自己的专辑。iOS 8照片框架:获取相册的特定列表

我使用下面的代码...除了我自己的专辑外,我可以得到专辑,但是如何在自己的专辑中获得除了我的照片之外的所有照片的PHFetchResult?

谢谢。

PHFetchOptions *albumsFetchOption = [[PHFetchOptions alloc]init]; 
NSString *string = @"MyCam"; 
albumsFetchOption.predicate = [NSPredicate predicateWithFormat:@"title != %@",string]; 

PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:albumsFetchOption]; 

最后,我用的,而不是PHFetchResult NSArray中...

//获取所有

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]; 
       } 
    }]; 
}];