Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pcccccc opened this issue Jun 4, 2020 · 0 comments
Open

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

pcccccc opened this issue Jun 4, 2020 · 0 comments

Comments

@pcccccc
Copy link

pcccccc commented Jun 4, 2020

可以尝试一下下面的方法

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 pcccccc changed the title 目前获取磁盘空间的方法可能会不太准确 目前获取磁盘剩余空间的方法可能会不太准确 Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant