4

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?

Jørgen R
  • 10,568
  • 7
  • 42
  • 59
Matt S.
  • 13,305
  • 15
  • 73
  • 129
  • Is the delegate method `-scannerDeviceView:didEncounterError:` ever called? – Tim Sep 12 '12 at 03:03
  • It does not. I have an IKScannerDeviceView and I have its delegate set to my AppDelegate (for now) and the app delegate does implement `IKScannerDeviceViewDelegate`, however `-scannerDeviceView:didEncounterError:` never gets called, both with a scanner plugged in and without one plugged in. – Matt S. Sep 13 '12 at 13:03

1 Answers1

8

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!

Matt S.
  • 13,305
  • 15
  • 73
  • 129
  • Thanks to your answer, my scanner will scan, but scannerDeviceView…didScan gets called with nil URL, fileData, and error. – Rick Jan 29 '17 at 03:15