Created
June 20, 2012 01:15
-
-
Save dhoerl/2957534 to your computer and use it in GitHub Desktop.
Getting the Free Disk Space on an iOS device
This file contains hidden or 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)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