How to detect total available/free disk space on the iPhone/iPad device?

后端 未结 18 1752
别跟我提以往
别跟我提以往 2020-11-22 11:14

I\'m looking for a better way to detect available/free disk space on the iPhone/iPad device programmatically.
Currently I\'m using the NSFileManager to detect the disk s

18条回答
  •  孤街浪徒
    2020-11-22 11:53

    Important clarification (at least for me). If I connect my iPod to my Mac this is the info showed by iTunes App.

    iPod memory informations from iTunes app

    When I use the above code:

    long long freeSpace = [[[[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil]
                                objectForKey:NSFileSystemFreeSize] longLongValue];
    
    NSString *free1 = [NSByteCountFormatter stringFromByteCount:freeSpace countStyle:NSByteCountFormatterCountStyleFile];
    
    [label1 setText:free1];
    
    NSString *free2 = [NSByteCountFormatter stringFromByteCount:freeSpace countStyle:NSByteCountFormatterCountStyleBinary];
    
    [label2 setText:free2];
    

    The countStyle NSByteCountFormatterCountStyleFile show me: 17,41 GB

    The countStyle NSByteCountFormatterCountStyleBinary show me: 16,22 GB

    16,22 GB (NSByteCountFormatterCountStyleBinary) It is EXACTLY the number that iTunes App show me when I connect my iPod to my Mac.

提交回复
热议问题