LLDebugTool icon indicating copy to clipboard operation
LLDebugTool copied to clipboard

目前获取磁盘剩余空间的方法可能会不太准确

Open pcccccc opened this issue 4 years ago • 0 comments

可以尝试一下下面的方法

unsigned long long totalFreeSpace = 0; if (@available(iOS 11.0, *)) {

    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:NSTemporaryDirectory()];
    NSDictionary *results = [fileURL resourceValuesForKeys:@[NSURLVolumeAvailableCapacityForImportantUsageKey] error:nil];
    totalFreeSpace = [results[NSURLVolumeAvailableCapacityForImportantUsageKey] longLongValue];
}else {
    
    NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
    totalFreeSpace = [[fattributes objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
}
return totalFreeSpace;

pcccccc avatar Jun 04 '20 07:06 pcccccc