Oli*_*ver 6 filesystems iphone diskspace itunes objective-c
我使用这种方法来获取磁盘上的可用空间,从一些研究后发现的代码中提取.
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];
}
Run Code Online (Sandbox Code Playgroud)
我想知道为什么在运行这个时,它给了我3660062720.000000字节的可用空间,这将给出3,408699035644531 Gb(/ 1024/1024/1024)
但是看看我的iPhone设置 - >一般信息(还有iTunes),我说我的iPhone只剩下3.2 Gb了.
哪里出错了?
似乎有时可用空间报告不正确https://discussions.apple.com/thread/2566412?threadID=2566412
编辑:我尝试了以下代码,发现在我的设备上也存在约 200MB 的差异。也许该存储空间是以某种方式为系统保留的?
NSDictionary *fsAttr = [[NSFileManager defaultManager] fileSystemAttributesAtPath:NSHomeDirectory()];
unsigned long long freeSpace = [[fsAttr objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
NSLog(@"%llu", freeSpace);
NSLog(@"%f", freeSpace / 1073741824.0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3142 次 |
| 最近记录: |