2010-04-09 42 views
1

我開發一個iPhone應用程序的表現中,我想知道在iPhone上可用的磁盤空間。我知道,很多應用程序都這樣做,但我似乎無法找到該位的任何地方我如何找出iphone的磁盤空間?

回答

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; 
}