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

[代码]悦德财富:https://www.yuedecaifu.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-(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;
         
        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"];
         
        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;
}

iphone获取当前磁盘信息的更多相关文章

  1. iphone获取sim卡信息

    /* iphone获取sim卡信息 1.加入一个Framework(CoreTelephony.framework). 2.引入头文件 #import <CoreTelephony/CTTele ...

  2. iphone获取当前流量信息

    通过读取系统网络接口信息,获取当前iphone设备的流量相关信息,统计的是上次开机至今的流量信息. 代码 悦德财富:https://yuedecaifu.com 1 2 3 4 5 6 7 8 9 1 ...

  3. C#获取本地磁盘信息【转载】

      直接上干货简单易懂 //磁盘监控(远程/本地)//需要引用System.Management.dllpublic class RemoteMonitoring{private static str ...

  4. C#获取本地磁盘信息

    直接上干货简单易懂 //磁盘监控(远程/本地) //需要引用System.Management.dll public class RemoteMonitoring { private static s ...

  5. linux下 stat statfs 获取 文件 磁盘 信息

    stat函数讲解 表头文件:    #include <sys/stat.h>              #include <unistd.h> 定义函数:    int st ...

  6. Powershell获取磁盘信息

    使用Powershell完成系统管理实在是太方便了,磁盘信息获取只需几行代码即可. 1: $DiskCount = ((Get-WmiObject -Class Win32_DiskDrive).Ca ...

  7. C#获取本机磁盘信息

    照着书敲的.留作笔记吧. using System; using System.Collections.Generic; using System.Linq; using System.Text; u ...

  8. C++ 通过WIN32 API 获取逻辑磁盘详细信息

    众所周知,在微软的操作系统下编写应用程序,最主要的还是通过windows所提供的api函数来实现各种操作的,这些函数通常是可以直接使用的,只要包含windows.h这个头文件, 下载源文件 今天我们主 ...

  9. C++通过WIN32 API获取逻辑磁盘详细信息

      众所周知,在微软的操作系统下编写应用程序,最主要的还是通过windows所提供的api函数来实现各种操作的,这些函数通常是可以直接使用的,只要包含windows.h这个头文件. 今天我们主要介绍的 ...

随机推荐

  1. 转!!Java 基础面试题的剖析: short s1=1;s1 = s1 +1 报错? s1+=1 呢

    short s1=1;s1 = s1 +1会报错吗?    package common; public class ShortTypeTest { /* * @param args */ publi ...

  2. matlab灰度变彩色+白平衡算法实现

    % matlab彩色图像分离通道并合并成处理后的彩色图像(彩色变灰度再变彩色) % 白平衡算法(灰度世界法)消除RGB受光照影响 clear all; close all; %读入原始图像 srcIm ...

  3. 如何使用 declare-styleable

    如何使用 declare-styleable 在创建 xml 到 objectName/res/values/ 命名为 attrs.xml 编辑文件内容为(示例)<?xml version=&q ...

  4. APMServ本地搭建网站最好用的软件

    APMServ 5.2.6 是一款拥有图形界面的快速搭建Apache 2.2.9.PHP 5.2.6.MySQL 5.1.28&4.0.26.Nginx 0.7.19.Memcached 1. ...

  5. iOS 沙盒(sandbox)机制和文件操作

    本文参看了 http://www.uml.org.cn/mobiledev/201209211.asp#1 这篇文章中的介绍,尊重原著. 1.IOS沙盒机制 IOS应用程序只能在本应用程序中创建的文件 ...

  6. Java软件工程师全栈技能

    1.前端基础技能,掌握html.js.css,会用jquery.bootstrap. 2.前端技能升级,会用echart.BMap等等. 3.前端高级技能,熟练使用angularjs等等. 4.服务端 ...

  7. div滚动条演示

    <!DOCTYPE html> <html> <head> <meta charset="gb2312" /> <title& ...

  8. 例题:计算运费。c#语言基础,比较简单。看代码输入格式和方法。同样方法可以做一个 出租车打车的程序

    while (true) { Console.WriteLine("请输入行李重量"); double k = Convert.ToDouble(Console .ReadLine ...

  9. 清理无用的CSS样式的几个工具(转)

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  10. 利用mycat实现mysql数据库读写分离

    1.这里是在mysql主从复制实现的基础上,利用mycat做读写分离,架构图如下: 2.Demo 2.1 在mysql master上创建数据库创建db1 2.2 在数据库db1创建表student ...