jAmi
jAmi

Reputation: 779

how do i find out iphone Disk Space?

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

Upvotes: 1

Views: 922

Answers (1)

Mihir Mehta
Mihir Mehta

Reputation: 13833

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

Upvotes: 4

Related Questions