iPhone - 设备上剩余的可用空间报告不正确(+- 200 Mb 差异)

发布于 2025-01-05 01:21:57 字数 730 浏览 5 评论 0原文

我使用这种方法来获取磁盘上的可用空间,这是从经过一些研究后发现的代码中提取的。

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾`听者〃 2025-01-12 01:21:58

有时,可用空间的报告似乎不正确 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); 

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); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文