Skip to content

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

@pcccccc

Description

@pcccccc

可以尝试一下下面的方法

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions