我如何找到iphone磁盘空间?

时间:2010-04-09 10:02:09

标签: iphone

我正在创建一个iphone性能应用程序,我想知道iPhone上的磁盘空间......我知道很多应用程序都这样做但我似乎无法在任何地方找到它

1 个答案:

答案 0 :(得分:4)

+(float)getTotalDiskSpaceInBytes {
    float totalSpace = 0.0f;
    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];
        totalSpace = [fileSystemSizeInBytes floatValue];
    } else {
        DLog(@"Error Obtaining File System Info: Domain = %@, Code = %@", [error domain], [error code]);
    }

    return totalSpace;
}  
相关问题