I want to get the Storage Sizes of each Applications in iPhone through objective C.
Any one help to get like this....
-
1Have you tried iterating through your directories and files in the bundle, library, documents and cache directory? – basvk Mar 07 '12 at 16:33
-
Yes, but i can't get the exact directories and file in the bundle. Can you pls help to find out..? – Suresh D Mar 08 '12 at 05:23
-
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 this – basvk Mar 08 '12 at 07:28
-
1Thank you @basvk , Let me try...! – Suresh D Mar 08 '12 at 08:27
-
1see that link http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html it may help you. – Prabhjot Singh Gogana May 18 '12 at 05:37
3 Answers
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.
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);
}

- 888
- 6
- 24
-
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 : 0 – Stalin Pusparaj Jul 18 '16 at 14:25
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.

- 2,579
- 17
- 27