iOS----获取设备可用容量及总容量(G)

/**

*  获取设备可用容量

*

*  @return 可用容量(G)

*/

+(float)getFreeDiskSize{

    float freeSize;

    NSError * error;

    NSDictionary * infoDic = [[NSFileManager defaultManager] attributesOfFileSystemForPath: NSHomeDirectory() error: &error];

    if (infoDic) {

        NSNumber * fileSystemFreeSize = [infoDic objectForKey: NSFileSystemFreeSize];

        freeSize = [fileSystemFreeSize floatValue]/1024.0f/1024.0f/1024.0f;

        return freeSize;

    } else {

        return 0;

    }

}

-------------------------------------------

/**

*  获取设备总容量

*

*  @return 总容量(G)

*/

+(float)getTotalDiskSize{

    float totalSize;

    NSError * error;

    NSDictionary * infoDic = [[NSFileManager defaultManager] attributesOfFileSystemForPath: NSHomeDirectory() error: &error];

    if (infoDic) {

        NSNumber * fileSystemSizeInBytes = [infoDic objectForKey: NSFileSystemSize];

        totalSize = [fileSystemSizeInBytes floatValue]/1024.0f/1024.0f/1024.0f;

        return totalSize;

    } else {

        //NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);

        return 0;

    }

}

你可能感兴趣的:(iOS----获取设备可用容量及总容量(G))