`
siruoxian
  • 浏览: 231491 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

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;

}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics