Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.