Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Device free space and sandbox space used

I'm trying to get the free space on the device and the amount of space my sandbox is using. Any thoughts?

Thanks, Rick

like image 516
Rick Avatar asked Feb 26 '11 00:02

Rick


1 Answers

In Objective-C you can get the available file system space with NSFileManager:

NSFileManager* filemgr = [NSFileManager defaultManager];

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = [paths objectAtIndex:0];            

NSDictionary* fsAttr = [filemgr attributesOfFileSystemForPath:docDirectory error:NULL];

unsigned long long freeSize = [(NSNumber*)[fsAttr objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];

To get the amount of space your app is using read this question: Calculate the size of a folder

like image 68
Felix Avatar answered Sep 28 '22 15:09

Felix