I want to get the Storage Sizes of each Applications in iPhone through objective C.
Any one help to get like this....
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);
}
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.
© 2022 - 2024 — McMap. All rights reserved.