iPhone-设备上剩余的可用空间报告不正确(+;-200 Mb差异)
我使用这种方法获取磁盘上的可用空间,这是从一些研究后发现的代码中提取出来的iPhone-设备上剩余的可用空间报告不正确(+;-200 Mb差异),iphone,objective-c,filesystems,itunes,diskspace,Iphone,Objective C,Filesystems,Itunes,Diskspace,我使用这种方法获取磁盘上的可用空间,这是从一些研究后发现的代码中提取出来的 float freeSpace = -1.0f; NSError* error = nil; NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSDictionary* dictionary = [[NSFileManager de
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字节的可用空间
这将产生3408699035644531 Gb(/1024/1024/1024)
但看看我的iPhone设置->常规信息(还有iTunes),我听说我的iPhone只剩下3.2GB了
错误在哪里?似乎有时可用空间报告不正确 编辑:我尝试了以下代码,并注意到在我的设备上,也有一个~200MB的差异。也许存储是为系统保留的
NSDictionary *fsAttr = [[NSFileManager defaultManager] fileSystemAttributesAtPath:NSHomeDirectory()];
unsigned long long freeSpace = [[fsAttr objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
NSLog(@"%llu", freeSpace);
NSLog(@"%f", freeSpace / 1073741824.0);
询问。但根据我的iPhone,不仅仅是iTunes,它也是3.2GB。。。该方法返回3.4…更新了我的答案,我也注意到了一个不同的问题—关于200MB的差异没有新闻?@flchaux这个答案几乎肯定不再适用,因为新设备有不同的文件系统(APFS)。我一直在用10.3 ios版本和APFS解决这个问题。你找到答案了吗?