iPhone - Free space left on device reported incorrectly (+- 200 Mb difference)

爱⌒轻易说出口 提交于 2019-11-26 23:23:09

问题


I use this method to get the free space on the disk, extracted from a code found after some researches.

    float freeSpace = -1.0f;  
    NSError* error = nil;  
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
    NSDictionary* dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];  

    if (dictionary) {  
        NSNumber* fileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];  
        freeSpace = [fileSystemSizeInBytes floatValue];  
    }

I wonder why when runing this, it gives me a free space of 3660062720.000000 bytes that would give 3,408699035644531 Gb (/1024/1024/1024)

But looking into my iPhone setting -> general info (and also into iTunes), I'm said that my iPhone has only 3.2 Gb left.

Where is the mistake ?


回答1:


It appears that sometimes the free space is reported incorrectly https://discussions.apple.com/thread/2566412?threadID=2566412

EDIT: I tried the following code and noticed that on my device, there was also a ~200MB discrepancy. Maybe that storage is reserved for the system somehow?

NSDictionary *fsAttr = [[NSFileManager defaultManager] fileSystemAttributesAtPath:NSHomeDirectory()];

unsigned long long freeSpace = [[fsAttr objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];

NSLog(@"%llu", freeSpace);
NSLog(@"%f", freeSpace / 1073741824.0); 


来源:https://stackoverflow.com/questions/9270027/iphone-free-space-left-on-device-reported-incorrectly-200-mb-difference

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