`

iphone 获取手机当前内存大小

    博客分类:
  • ios
 
阅读更多

+ (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;

}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics