tags:

views:

148

answers:

1

I am creating an iphone performance app in which I would like to know the Disk Space available on iphone ... I know that a lot of apps do this but I cant seem to find this bit anywhere

+1  A: 
+(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;
}  
mihirpmehta