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 ?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With