为什么NSFileSystemFreeSize的值与iOS设置中报告的可用大小不同? [英] Why does the value from NSFileSystemFreeSize differ from the free size reported in the iOS Settings?

查看:554
本文介绍了为什么NSFileSystemFreeSize的值与iOS设置中报告的可用大小不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我用来为我的应用获取iOS设备上的可用存储空间的方法:

The following is what I use to get the available storage space on an iOS device for my app:

NSDictionary *dict = [[NSFileManager defaultManager] fileSystemAttributesAtPath:@"/var"];
NSNumber *freeSpace = [dict valueForKey:@"NSFileSystemFreeSize"];

但是,值 freeSpace 不对应使用设置应用中显示的那个。该值始终大于设置显示的值。例如, freeSpace 大约是600,000,000字节,其中设置显示357 MB。

However, the value freeSpace does not correspond with the one shown in the Settings app. The value is always greater than the value shown by Settings. For example, freeSpace is approximately 600,000,000 bytes, where Settings shows 357 MB.

为什么这样,我该怎么办?获取与Settings显示的值相同的值?

Why is this and how can I get the same value as the value shown by Settings?

推荐答案

我打赌你使用32位整数或浮点类型来存储文件系统大小值。如果文件大小足够大,则会失败。相反,使用unsigned long long或long double类型来存储这些值。

I bet that you are using 32-bit integer or float types to store your file system size values. This will fail with large enough file sizes. Instead, use unsigned long long or long double types to store these values.

请参阅此答案了解如何准确读取这些文件大小。对该答案和其他答案的评论表明,这将返回一个与iTunes和其他工具报告的免费大小相匹配的值。

See the corrected version of this answer for how to read these file sizes accurately. The comments on that answer and others there indicate that this returns a value which matches the free size reported by iTunes and other tools.

这篇关于为什么NSFileSystemFreeSize的值与iOS设置中报告的可用大小不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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