Skip to content

Crashed when album is empty #6

@heefan

Description

@heefan

Hi bro,

Please test the following scenario which I got crashed.

  1. create an empty folder in Photos(Apple App), let's call it 'test'
  2. run your application

Result : Application will crash when loading photo.
Reason: Application tries to create thumbnail, but the empty folder haven't had photo yet. It means the operation is on the nil pointer.

Source : AssetHelper.m

- (NSDictionary *)getGroupInfo:(NSInteger)nIndex
{ 
    return @{@"name" : [_assetGroups[nIndex] valueForProperty:ALAssetsGroupPropertyName],
             @"count" : @([_assetGroups[nIndex] numberOfAssets]),
             @"thumbnail" : [UIImage imageWithCGImage:[(ALAssetsGroup*)_assetGroups[nIndex] posterImage]]};
}

My temp solution

- (NSDictionary *)getGroupInfo:(NSInteger)nIndex
{
     if ([_assetGroups[nIndex] numberOfAssets] != 0)  {
         return @{@"name" : [_assetGroups[nIndex] valueForProperty:ALAssetsGroupPropertyName],
             @"count" : @([_assetGroups[nIndex] numberOfAssets]),
             @"thumbnail" : [UIImage imageWithCGImage:[(ALAssetsGroup*)_assetGroups[nIndex] posterImage]]};
     } else {
           return @{@"name" : [_assetGroups[nIndex] valueForProperty:ALAssetsGroupPropertyName],
             @"count" : @([_assetGroups[nIndex] numberOfAssets])};
    }
}

Workflow:
Check whether the folder has photo,

  1. if has, work as previous
  2. if not, don't generate image for thumbnail.

Result:
UI will list the empty folder name as well.
It shows empty content if user clicks into the folder.

Plus:
And even you may not want to list the empty folder in the list, this depends on your designate UX, here I just give the report and simple solution.

Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions