Skip to content
This repository has been archived by the owner on Jul 16, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from talk-to/fix-mediatype-nil-crash-on-lib-update
Browse files Browse the repository at this point in the history
  • Loading branch information
dineshflock authored Jan 29, 2018
2 parents a0c9d3e + f8f3fbf commit 5ee98e8
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions GMImagePicker/GMAlbumsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ - (void)selectAllAlbumsCell {

-(void)updateFetchResults
{
if (self.picker.mediaTypes == nil || self.picker.mediaTypes.count < 1) {
return;
}
//What I do here is fetch both the albums list and the assets of each album.
//This way I have acces to the number of items in each album, I can load the 3
//thumbnails directly and I can pass the fetched result to the gridViewController.
Expand All @@ -141,18 +144,13 @@ -(void)updateFetchResults
//All album: Sorted by descending creation date.
NSMutableArray *allFetchResultArray = [[NSMutableArray alloc] init];
NSMutableArray *allFetchResultLabel = [[NSMutableArray alloc] init];
{
// Try to fix : http://crashes.to/s/302c7fc1638
if (![self.picker.mediaTypes isEqual:[NSNull null]] && self.picker != nil) {
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType in %@", self.picker.mediaTypes];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsWithOptions:options];
[allFetchResultArray addObject:assetsFetchResult];
[allFetchResultLabel addObject:NSLocalizedStringFromTableInBundle(@"picker.table.all-photos-label", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"All photos")];

}
}

PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType in %@", self.picker.mediaTypes];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsWithOptions:options];
[allFetchResultArray addObject:assetsFetchResult];
[allFetchResultLabel addObject:NSLocalizedStringFromTableInBundle(@"picker.table.all-photos-label", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"All photos")];

//User albums:
NSMutableArray *userFetchResultArray = [[NSMutableArray alloc] init];
Expand Down

0 comments on commit 5ee98e8

Please sign in to comment.