简体   繁体   中英

iOS 8 Photos framework: Get a specific list of albums

I am trying to get all get all photos by except for the photos in my own album. I try to get all the photos using the method in this answer. ios - Simple example to get list of photo albums? but I can't find an option to filtrate my own album.

I use the code like below...I can get the the albums except my own one,but how can I get PHFetchResult with all the photos except my the photos in my own album?

Thank you.

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

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

At last ,I use NSArray instead of PHFetchResult...

//fetch all

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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