开发者

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 iPhon开发者_运维技巧e SDK?


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜