iPhone - 设备上剩余的空间不正确(+ - 200 Mb差异) [英] iPhone - Free space left on device reported incorrectly (+- 200 Mb difference)
问题描述
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];
$ b 我想知道为什么在运行时会给我一个3660062720.000000字节的可用空间
,会给3,408699035644531 Gb(/ 1024/1024/1024)
但看着我的iPhone设置 - >一般信息(也进入iTunes) ,我说我的iPhone只剩下3.2GB。
错误在哪里?
解决方案似乎有时可用空间报告不正确 https: //discussions.apple.com/thread/2566412?threadID=2566412
编辑:我尝试了下面的代码,注意到在我的设备上,也有〜200MB的差异。也许这个存储是为系统预留的?
pre $ NSDictionary * fsAttr = [[NSFileManager defaultManager] fileSystemAttributesAtPath:NSHomeDirectory()];
unsigned long long freeSpace = [[fsAttr objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
NSLog(@%llu,freeSpace);
NSLog(@%f,freeSpace / 1073741824.0);
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 ?
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?
NSDictionary *fsAttr = [[NSFileManager defaultManager] fileSystemAttributesAtPath:NSHomeDirectory()];
unsigned long long freeSpace = [[fsAttr objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
NSLog(@"%llu", freeSpace);
NSLog(@"%f", freeSpace / 1073741824.0);
这篇关于iPhone - 设备上剩余的空间不正确(+ - 200 Mb差异)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!