How to get Storage Size of Applications programmatically in iPhone
Asked Answered
M

3

18

I want to get the Storage Sizes of each Applications in iPhone through objective C.
Any one help to get like this.... enter image description here

Morris answered 7/3, 2012 at 14:57 Comment(5)
Have you tried iterating through your directories and files in the bundle, library, documents and cache directory?Longdrawnout
Yes, but i can't get the exact directories and file in the bundle. Can you pls help to find out..?Morris
The files / directories in your bundle won't change, so you could "just" get the directory info of you xcode project and use that folder size as a starting point for your total space. And then increment it with the library, documents and cache folder. Maybe there is a better way, haven't got experience with thisLongdrawnout
Thank you @Longdrawnout , Let me try...!Morris
see that link landonf.bikemonkey.org/code/iphone/… it may help you.Fablan
D
3

Assuming you are developing for a jailbroken device (if not then it is impossible to access the applications on the device), the SpringBoard should have predefined methods for accessing the metadata of all the applications installed. If you look at headers of SBApplication.h then there are methods for getting the metadata.

Digged answered 28/3, 2012 at 5:55 Comment(0)
A
2
    NSString *folderPath = "give application path here"

Example: NSString *folderPath =@"/private/var/mobile/Applications/2B63FD7F-2082-415D-A00C-F07C4BE281AA/Example.app";

    NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil];

    NSEnumerator *filesEnumerator = [filesArray objectEnumerator];
    NSString *fileName;
    unsigned long long int fileSize = 0;

    while (fileName = [filesEnumerator nextObject])

    {
        NSDictionary *fileDictionary = [[NSFileManager defaultManager] fileAttributesAtPath:[folderPath stringByAppendingPathComponent:fileName] traverseLink:YES];

        NSLog(@" fileDictionary   %@",fileDictionary);

        fileSize += [fileDictionary fileSize];
    }

    NSLog(@" App Name and App size: %@ : %lld", folderPath,fileSize);

if you want to find all applications size, take all applications path in array, and write for loop statement for folder path

   NSArray *applicationsPath="Here array contain all applications path"
   for (int i=0; i<applicationPath.count; i++)
   {
    NSString *folderPath = [applicationPath objectAtIndex:i]

    NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil];

    NSEnumerator *filesEnumerator = [filesArray objectEnumerator];
    NSString *fileName;
    unsigned long long int fileSize = 0;

    while (fileName = [filesEnumerator nextObject])

    {
        NSDictionary *fileDictionary = [[NSFileManager defaultManager] fileAttributesAtPath:[folderPath stringByAppendingPathComponent:fileName] traverseLink:YES];

        NSLog(@" fileDictionary   %@",fileDictionary);

        fileSize += [fileDictionary fileSize];
    }

    NSLog(@" App Name and App size: %@ : %lld", folderPath,fileSize);
   }
Actinopod answered 4/2, 2013 at 7:33 Comment(1)
fileSize always return 0 2016-07-18 19:53:07.040[1136:209376] File type NSFileTypeDirectory 2016-07-18 19:53:07.504[1136:209376] POSIX Permissions 493 2016-07-18 19:53:12.028[1136:209376] App Name and App size: /private/var/containers/Bundle/Application/80948321-EC7D-40A6-8C4B-9A1D82FD31E6/MS.app : 0Stapler
L
0

Unless the device is jailbroken, you will be unable to access each Application's folder programmatically.

This is because each iOS application operates in a sandboxed environment, meaning your application can ONLY access assets within this directory. If the device is jailbroken, this requirement is removed and you are granted full access to the device's disk.

Left answered 27/3, 2012 at 14:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.