| 123456789101112131415161718192021222324252627282930313233343536 |
- //
- // DiskFreeSpaceManager.m
- // StudentDaya
- //
- // Created by Kyle on 2021/10/9.
- // Copyright © 2021 DayaMusic. All rights reserved.
- //
- #import "DiskFreeSpaceManager.h"
- @implementation DiskFreeSpaceManager
- + (CGFloat)QueryDiskSpaceFree {
- NSURL *fileUrl = [NSURL fileURLWithPath:NSHomeDirectory()];
- int64_t space = 0;
- if (@available(iOS 11.0, *)) {
- NSDictionary *spaceDict = [fileUrl resourceValuesForKeys:@[NSURLVolumeAvailableCapacityForImportantUsageKey] error:nil];
- space = [spaceDict[NSURLVolumeAvailableCapacityForImportantUsageKey] longLongValue];
-
- } else {
- NSError *error = nil;
- NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:&error];
- if (error) {
- return -1;
- }
- space = [[attrs objectForKey:NSFileSystemFreeSize] longLongValue];
- if (space < 0) {
- space = -1;
- }
- }
- CGFloat freeSize = space * 1.0 / 1024.0 / 1024.0 / 1024.0;
- NSLog(@"free size %f", freeSize);
- return freeSize;
- }
- @end
|