开发者

detect no disk space iPhone SDK

开发者 https://www.devze.com 2023-04-10 02:13 出处:网络
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 fo

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

精彩评论

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

关注公众号