Last active
August 29, 2015 14:04
-
-
Save lumaxis/6ce5c58c83bedc6d77dc to your computer and use it in GitHub Desktop.
iOS Calculate free disk space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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