Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

updateAssetCollections method is changed to show all albums that have… #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions QBImagePicker/QBAlbumsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Photos/Photos.h>
Expand Down Expand Up @@ -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];
// }
}];
}

Expand Down