Matt
Matt

Reputation: 1973

detect no disk space iPhone SDK

Suppose I need to write many images to iPhone file system. And I need to find I have enough space to write image to disk. Is it possible using iPhone SDK?

Upvotes: 4

Views: 1587

Answers (1)

Kenny Winker
Kenny Winker

Reputation: 12097

Yes, it is possible. See the following tutorial (found using the powerful "google" search engine) ;)

http://iphoneincubator.com/blog/device-information/how-to-obtain-total-and-available-disk-space-on-your-iphone-or-ipod-touch

Edit: added response re: writing UIImage to disk, with unknown available disk space:

Try-Catch a bad way of doing things. Exceptions in cocoa are only for truly exceptionally circumstances (i.e. crash-worthy). If you write your image using

NSData *imageData = [myImage UIImageJPEGRepresentation];

(or UIImagePNGRepresentation)

and then

NSError *error;
BOOL success = [imageData writeToFile:(NSString *)path options:(NSDataWritingOptions)mask error:&error];

Your BOOL failed will tell you if it worked, and error will contain an NSError object with a description of the error (don't test for error != nil though, that'll crash occasionally).

Upvotes: 5

Related Questions