From bc3627aa1f8bf432f5c9fb68bd8a72ec80e93335 Mon Sep 17 00:00:00 2001 From: DimaFr Date: Thu, 11 Aug 2016 17:52:21 +0300 Subject: [PATCH] updateAssetCollections method is changed to show all albums that have assets I have replaced code that filter albums in order to show all albums that have photos. Previously there were only "camera roll" and "Panoramas" (even empty), no custom users or other applications albums. --- QBImagePicker/QBAlbumsViewController.m | 30 +++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/QBImagePicker/QBAlbumsViewController.m b/QBImagePicker/QBAlbumsViewController.m index a08dfe28..3cbf2c68 100644 --- a/QBImagePicker/QBAlbumsViewController.m +++ b/QBImagePicker/QBAlbumsViewController.m @@ -5,6 +5,10 @@ // Created by Katsuma Tanaka on 2015/04/03. // Copyright (c) 2015 Katsuma Tanaka. All rights reserved. // +//dimafr: check if iOS9 or later +#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) + + #import "QBAlbumsViewController.h" #import @@ -158,16 +162,26 @@ - (void)updateAssetCollections for (PHFetchResult *fetchResult in self.fetchResults) { [fetchResult enumerateObjectsUsingBlock:^(PHAssetCollection *assetCollection, NSUInteger index, BOOL *stop) { - PHAssetCollectionSubtype subtype = assetCollection.assetCollectionSubtype; - - if (subtype == PHAssetCollectionSubtypeAlbumRegular) { + //dimafr check if album has pictures if yes display + PHFetchOptions *options; + if SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0") { + options.fetchLimit =1; + } + + PHFetchResult *fetch = [PHAsset fetchAssetsInAssetCollection: assetCollection options:options]; + if (fetch.firstObject != nil) { [userAlbums addObject:assetCollection]; - } else if ([assetCollectionSubtypes containsObject:@(subtype)]) { - if (!smartAlbums[@(subtype)]) { - smartAlbums[@(subtype)] = [NSMutableArray array]; - } - [smartAlbums[@(subtype)] addObject:assetCollection]; } + // dimafr old code + // PHAssetCollectionSubtype subtype = assetCollection.assetCollectionSubtype; + // if (subtype == PHAssetCollectionSubtypeAlbumRegular) { + // [userAlbums addObject:assetCollection]; + // } else if ([assetCollectionSubtypes containsObject:@(subtype)]) { + // if (!smartAlbums[@(subtype)]) { + // smartAlbums[@(subtype)] = [NSMutableArray array]; + // } + // [smartAlbums[@(subtype)] addObject:assetCollection]; + // } }]; }