How to get Storage Size of Applications programmatically in iPhone

自作多情 提交于 2019-12-04 09:01:34

问题


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


回答1:


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.




回答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);
   }



回答3:


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.



来源:https://stackoverflow.com/questions/9603776/how-to-get-storage-size-of-applications-programmatically-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!