ITPub博客

首页 > 应用开发 > IT综合 > 获取iphone磁盘总大小、已使用空间、空闲空间

获取iphone磁盘总大小、已使用空间、空闲空间

IT综合 作者:2323684401 时间:2014-06-26 20:51:07 0 删除 编辑
获取iphone磁盘总大小、已使用空间、空闲空间 
1. [代码][C/C++]代码     跳至 [1] [全屏预览]

-(float)getFreeDiskspace {
    float totalSpace;
    float totalFreeSpace;
    float totalUsedSpace;
    
    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];
        totalFreeSpace = [freeFileSystemSizeInBytes floatValue];
        totalUsedSpace = totalSpace - totalFreeSpace;
        
        float freePercent = totalFreeSpace/totalSpace;
        float usedPercent = totalUsedSpace/totalSpace;
        http://www.huiyi8.com/css3/
        freePercentLabel.text  = [[NSString stringWithFormat:@"%.2f",freePercent*100]    stringByAppendingString:@"%"];
        usedPercentLabel.text  = [[NSString stringWithFormat:@"%.2f",usedPercent*100]    stringByAppendingString:@"%"];
        totalSpaceLabel.text   = [[NSString stringWithFormat:@"%.2f",((totalSpace/1024.0f)/1024.0f/1024.0f)]     stringByAppendingString:@"GB"];
        usedSpaceLabel.text    = [[NSString stringWithFormat:@"%.2f",((totalUsedSpace/1024.0f)/1024.0f/1024.0f)] stringByAppendingString:@"GB"];
        freeSpaceLabel.text    = [[NSString stringWithFormat:@"%.2f",((totalFreeSpace/1024.0f)/1024.0f/1024.0f)] stringByAppendingString:@"GB"];
        css3特效
        NSLog(@"Memory Capacity of %f GB with %f GB Free memory available.", ((totalSpace/1024.0f)/1024.0f/1024.0f), ((totalFreeSpace/1024.0f)/1024.0f)/1024.0f);
    } else {  
        NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %@", [error domain], [error code]);  
    }  
    return totalFreeSpace;
} 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29658298/viewspace-1195220/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-05-14

  • 博文量
    28
  • 访问量
    36542