当前位置: 代码迷 >> Iphone >> iphone 获取手机现阶段内存大小
  详细解决方案

iphone 获取手机现阶段内存大小

热度:29   发布时间:2016-04-25 05:48:30.0
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;

}

?

  相关解决方案