Affordable storage on iphone

Is it possible to determine how much free storage is left on the iphone using iphone sdk? I would like to adapt the cache size depending on how much space is actually left.

+4
source share
2 answers

Yes, you can. Here's an example: Mac / iPhone: Show available disk space . They provide a class that you can plug in, but a lot of this just formats the result.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); struct statfs tStats; statfs([[paths lastObject] cString], &tStats); availableDisk = (float)(tStats.f_bavail * tStats.f_bsize); 
+3
source

Error checking ...

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); struct statfs tStats; float availableDisk = 0; if (statfs([[paths lastObject] cString], &tStats) != -1) availableDisk = (float)(tStats.f_bavail * tStats.f_bsize); 
+1
source

All Articles