Skip to content

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

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;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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