filter PHCollectionList

This commit is contained in:
yaw
2018-09-05 10:15:09 +08:00
parent 2d43ce29e3
commit d6b10944fe

View File

@@ -193,25 +193,33 @@
subtype:PHAssetCollectionSubtypeAlbumSyncedAlbum options:nil];
PHFetchResult *userCollections = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil];
NSArray *collectionsFetchResults = @[smartAlbums, userCollections, syncedAlbums];
NSArray *allAlbums = @[smartAlbums, userCollections, syncedAlbums];
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
if(self.selectMode==100){
options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %ld", PHAssetMediaTypeImage];
}else if(self.selectMode==102){
options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %ld", PHAssetMediaTypeVideo];
}
for (int i = 0; i < collectionsFetchResults.count; i ++) {
PHFetchResult *fetchResult = collectionsFetchResults[i];
for (int x = 0; x < fetchResult.count; x ++) {
for (PHFetchResult *fetchResult in allAlbums) {
for (PHAssetCollection *collection in fetchResult) {
// PHCollectionList
if (![collection isKindOfClass:[PHAssetCollection class]]) continue;
//
if (collection.estimatedAssetCount <= 0) continue;
if (collection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumAllHidden) continue; //
if (collection.assetCollectionSubtype == 1000000201) continue; //
PHAssetCollection *collection = fetchResult[x];
PHFetchResult *group = [PHAsset fetchAssetsInAssetCollection:collection options:options];
if([group count]>0){
[albumsTitlelist addObject:collection.localizedTitle];
[dataSource addObject:group];
}
}
}
}
_manager = [PHImageManager defaultManager];