Method to know the freesize and total space in an apple device

-(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) {
        //gives total space in the device
        NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
        //gives the free space in device
        NSNumber *usedSpaceInBytes = [dictionary objectForKey: NSFileSystemFreeSize];

        totalSpace = [fileSystemSizeInBytes floatValue];
    } else {
        //DLog(@”Error Obtaining File System Info: Domain = %@, Code = %@”, [error domain], [error code]);
        NSLog(@”Error Obtaining File System Info: Domain = %@, Code = %ld”, [error domain], (long)[error code]);
    }
    
    return totalSpace;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s