macoscocoascanningikscannerdeviceview

How to use IKScannerDeviceView in Cocoa


How can I use IKScannerDeviceView to scan a document inside of my app?

I tried adding an IKScannerDeviceView into my view through IB and setting its delegate to my app delegate (which implements the IKScannerDeviceViewDelegate), but when I run the app I get a view with the buttons Show Details and Scan, and only Show Details is enabled and when I click it nothing happens.

I have a scanner plugged in and I can scan through Image Capture, but not through my app.

Does anybody have a good tutorial on how to use it?


Solution

  • I was finally able to figure out how to use IKScannerDeviceView.

    Your class must implement the following delegates:

    IKScannerDeviceViewDelegate, ICScannerDeviceDelegate, ICDeviceBrowserDelegate
    

    and you need to have an IKScannerDeviceView in your window, with its delegate set to the class implementing IKScannerDeviceViewDelegate

    To start using it, you must create an ICDeviceBrowser like so:

        ICDeviceBrowser *mDeviceBrowser = [[ICDeviceBrowser alloc] init];
        mDeviceBrowser.delegate = self;
        mDeviceBrowser.browsedDeviceTypeMask = ICDeviceLocationTypeMaskLocal|ICDeviceLocationTypeMaskRemote|ICDeviceTypeMaskScanner;
        [mDeviceBrowser start];
    

    Then implement the delegate methods in a manner similar to this:

    - (void)scannerDeviceDidBecomeAvailable:(ICScannerDevice*)scanner;
    {
        [scanner requestOpenSession];
    }
    - (void)deviceBrowser:(ICDeviceBrowser*)browser didAddDevice:(ICDevice*)addedDevice moreComing:(BOOL)moreComing
    {
        if ( (addedDevice.type & ICDeviceTypeMaskScanner) == ICDeviceTypeScanner )
        {
            [scannerView setScannerDevice:(ICScannerDevice*)addedDevice];
        }
    }
    -(void)didRemoveDevice:(ICDevice*)removedDevice
    {
        [removedDevice requestCloseSession];
    }
    

    Then if all goes right, your IKScannerDeviceView will be able to interact with your scanner!