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;
}