检测没有磁盘空间的iPhone SDK [英] detect no disk space iPhone SDK

查看:119
本文介绍了检测没有磁盘空间的iPhone SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我需要将许多图像写入iPhone文件系统。而且我需要找到足够的空间来将图像写入磁盘。是否可以使用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?

推荐答案

是的,这是可能的。请参阅以下教程(使用功能强大的google搜索引擎找到);)

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

http://iphoneincubator.com/blog/device-information/how在你的iphone-or-ipod-touch 上获得全部和可用的磁盘空间

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

编辑:添加了响应:使用未知的可用磁盘空间将UIImage写入磁盘:

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];

(或UIImagePNGRepresentation)

(or UIImagePNGRepresentation)

然后

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

您的 BOOL 失败会告诉你它是否有效,错误将包含一个 NSError 对象错误的描述(不要测试错误!= nil 但是,偶尔会崩溃)。

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

这篇关于检测没有磁盘空间的iPhone SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆