iphone 获取手机当前内存大小

+ (float)getFreeDiskspace{

float totalSpace;

float totalFreeSpace=0.f;

NSError *error = nil; 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error]; 

if (dictionary) { 

NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize]; 

NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];

totalSpace = [fileSystemSizeInBytes floatValue]/1024.0f/1024.0f/1024.0f;

totalFreeSpace = [freeFileSystemSizeInBytes floatValue]/1024.0f/1024.0f/1024.0f;

NSLog(@"Memory Capacity of %f GB with %f GB Free memory available.", totalSpace, totalFreeSpace);

} else { 

NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %@", [error domain], [error code]); 

return totalFreeSpace;

}

 

你可能感兴趣的:(iPhone)