Thursday, July 24, 2014

Check disk space capacity

 //Invoke freeDiskspace function
 [self freeDiskspace];


//Check for Disk Space capacity
- (void)freeDiskspace {
    
    totalSpace = 0;
    totalFreeSpace = 0;
    
    __autoreleasing NSError *error = nil;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject]
                                                                            error: &error];
        
    if (dictionary) {
        
        fileSystemSizeInBytes = 0;
        freeFileSystemSizeInBytes = 0;
        
        fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
        freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];

        // freeFileSystemSizeInBytes = [NSNumber numberWithInt:1293408];
        
        NSLog(@"fileSystemSizeInBytes : %@  freeFileSystemSizeInBytes : %@ ",fileSystemSizeInBytes,freeFileSystemSizeInBytes);
        
        totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
        totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
                      
        NSLog(@"Memory Capacity of %llu MB with %llu MB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));
        
    } else {
        
        NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %d", [error domain], (int)[error code]);
    }

}

No comments:

Post a Comment