Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing out of space conditions in iPhone

Tags:

iphone

testing

What's the easiest way to simulate or create out of space conditions in iPhone, both on the simulator and on an actual device?

I would like to test the code that handles such situations.

like image 298
hpique Avatar asked Nov 15 '22 11:11

hpique


1 Answers

Here is the code sample to calculate space:

#include<sys/param.h>  
#include <sys/mount.h>  

+(float)getTotalDiskSpaceInBytes {  
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
    struct statfs tStats;  
    statfs([[paths lastObject] cString], &tStats);  
    float totalSpace = (float)(tStats.f_blocks * tStats.f_bsize);  

   return totalSpace;  

}

Please note this is running perfectly for 3.x device. I am not sure for 2.x devices.


Thanks,
Jim.

like image 142
Jim Avatar answered Dec 19 '22 11:12

Jim