1偎球、獲取總空間(單位:G)
+ (CGFloat)totalDiskSpace {
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *total = [dictionary objectForKey:NSFileSystemSize];
return [total unsignedLongLongValue] * 1.0/1024.0/1024.0/1024.0;
}
return 0;
}
2、獲取可用空間大惺ァ(單位:M)
+ (CGFloat)freeDiskSpace {
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *free = [dictionary objectForKey:NSFileSystemFreeSize];
return [free unsignedLongLongValue] * 1.0/1024.0/1024.0;
}
return 0;
}