iPhone - 设备上剩余的可用空间报告不正确(+- 200 Mb 差异)
我使用这种方法来获取磁盘上的可用空间,这是从经过一些研究后发现的代码中提取的。
float freeSpace = -1.0f;
NSError* error = nil;
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary* dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber* fileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
freeSpace = [fileSystemSizeInBytes floatValue];
}
我想知道为什么运行这个时,它给了我 3660062720.000000 字节的可用空间 这将给出 3,408699035644531 Gb (/1024/1024/1024)
但查看我的 iPhone 设置 ->一般信息(以及 iTunes),据说我的 iPhone 只剩下 3.2 GB。
错误在哪里?
I use this method to get the free space on the disk, extracted from a code found after some researches.
float freeSpace = -1.0f;
NSError* error = nil;
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary* dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber* fileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
freeSpace = [fileSystemSizeInBytes floatValue];
}
I wonder why when runing this, it gives me a free space of 3660062720.000000 bytes
that would give 3,408699035644531 Gb (/1024/1024/1024)
But looking into my iPhone setting -> general info (and also into iTunes), I'm said that my iPhone has only 3.2 Gb left.
Where is the mistake ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有时,可用空间的报告似乎不正确 https://discussions.apple.com/thread /2566412?threadID=2566412
编辑:我尝试了以下代码并注意到在我的设备上,还有一个 ~200MB 差异。也许该存储空间是以某种方式为系统保留的?
It appears that sometimes the free space is reported incorrectly https://discussions.apple.com/thread/2566412?threadID=2566412
EDIT: I tried the following code and noticed that on my device, there was also a ~200MB discrepancy. Maybe that storage is reserved for the system somehow?