tags:

views:

39

answers:

1

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.

+1  A: 

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.

Jim
Thanks for the code Jim. The wording of my question was a bit misleading. I meant how you simulate a condition in which the device does not have much space left, to effectively test code like yours.
hgpc
you can try to store large media files(audio/video) into your document folder of your application that will generate out of space conditions in iPhone. Or other way generate one large log file in your document and try to add all the log message to the same file it will again raise out of space exception.
Jim