Skip to content

Instantly share code, notes, and snippets.

@maojj
Created August 12, 2014 07:48
Show Gist options
  • Save maojj/146412c32f90e473ad81 to your computer and use it in GitHub Desktop.
Save maojj/146412c32f90e473ad81 to your computer and use it in GitHub Desktop.
get Free Disk space on iphone, see: http://stackoverflow.com/a/8036586
-(uint64_t)getFreeDiskSpace {
uint64_t totalSpace = 0;
uint64_t totalFreeSpace = 0;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
NSLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));
} 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