0

Till iOS 7 we were using Assets Library Framework to get the total size of photos and videos in iOS device, look here : How to find total size for images and videos inside photo library in iOS

Can anyone please help me do the same using Photos Framework as Assets Library Framework is deprecated. Also how can I calculate the total size if there are large number of photos in a faster manner. You can see in this app : MobiShield for iPhone here if you go to More > Disk you can see that the developer is calculating the total photos size and videos size in 2 seconds. How can I achieve this ? In Objective - C.

Omkar Jadhav
  • 1,046
  • 3
  • 16
  • 41

2 Answers2

0

User Photo Assets (I have not used yet but this is IOS 8 requirement) or ALASSETS that is deprecated but still working with current versions , this will give you the file information.

codelover
  • 1,113
  • 10
  • 28
0

Use these :

- (NSUInteger)updateVideoCount
{
    ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
    if (status==ALAuthorizationStatusDenied) {
        [self goToSettingsAlert];
    }
videoCount = 0;
totalVideoSize = 0;

ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];

[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    [group setAssetsFilter:[ALAssetsFilter allVideos]];
    [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) {
        if (asset)
        {
            NSString *type = [asset  valueForProperty:ALAssetPropertyType];
            if ([type isEqualToString:ALAssetTypeVideo])
            {
                videoCount++;

                ALAssetRepresentation *rep = [asset defaultRepresentation];
                totalVideoSize += rep.size;
            }

        }
        else
        {

        }
    }];
    if(group==nil)
    {
        [self loadTable];
        descTable.hidden = NO;
        [descTable reloadData];
    }
} failureBlock:^(NSError *error) {
}];

return 0;

}

- (NSUInteger)updatePictureCount
{
    photoCount = 0;
    totalPictureSize = 0;

    ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];

    [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
        [group setAssetsFilter:[ALAssetsFilter allPhotos]];
        [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) {
            if (asset)
            {
                NSString *type = [asset  valueForProperty:ALAssetPropertyType];
                if ([type isEqualToString:ALAssetTypePhoto])
                {
                    photoCount++;

                    ALAssetRepresentation *rep = [asset defaultRepresentation];
                    totalPictureSize += rep.size;
                }

            }

            else
            {

            }
        }];
        if(group==nil)
        {

            [self loadTable];
            descTable.hidden = NO;
            [descTable reloadData];
        }
    } failureBlock:^(NSError *error) {

    }];

    return 0;
}
Omkar Jadhav
  • 1,046
  • 3
  • 16
  • 41