Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 606
Oliver Avatar asked Feb 14 '12 00:02

Oliver


1 Answers

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); 
like image 94
danielbeard Avatar answered Oct 06 '22 01:10

danielbeard