Skip to content

Instantly share code, notes, and snippets.

@dhoerl
Created June 20, 2012 01:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dhoerl/2957534 to your computer and use it in GitHub Desktop.
Save dhoerl/2957534 to your computer and use it in GitHub Desktop.
Getting the Free Disk Space on an iOS device
- (uint64_t)freeDiskspace
{
uint64_t totalFreeSpace = 0;
__autoreleasing NSError *error = nil;
NSString *path = [self applicationDocumentsDirectory];
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:path error: &error];
if (dictionary) {
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
#ifndef NDEBUG
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
uint64_t totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
NSLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));
#endif
} else {
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %@", [error domain], [error code]);
}
return totalFreeSpace;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment