方法一
#pragma mark - 手机可用内存
- (double)availableMemory
{
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO,(host_info_t)&vmStats,&infoCount);
if (kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
NSLog(@"%f",((vm_page_size *vmStats.free_count) / 1024.0) / 1024.0);
return ((vm_page_size *vmStats.free_count) / 1024.0) / 1024.0;
}
方法二
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *attributes = [fileManager attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
NSLog(@"容量%.2fG",[attributes[NSFileSystemSize] doubleValue] / (powf(1024, 3)));
NSLog(@"可用%.2fG",[attributes[NSFileSystemFreeSize] doubleValue] / powf(1024, 3));