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

后端 未结 1 1940
北荒
北荒 2020-12-06 13:24

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 = n         


        
相关标签:
1条回答
  • 2020-12-06 14:11

    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); 
    
    0 讨论(0)
提交回复
热议问题