How to use IKScannerDeviceView in Cocoa

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

I tried to add IKScannerDeviceView to my view via IB and set its delegate for my application delegate (which implements IKScannerDeviceViewDelegate), but when I start the application, I get the view with the Show Details and Scan buttons, and only Show Details enabled, and when I click on him, nothing happens.

I have a scanner, and I can scan through Image Capture, but not through my application.

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

+4
source share
1 answer

Finally, I was able to figure out how to use IKScannerDeviceView.

The following delegates should be implemented in your class:

 IKScannerDeviceViewDelegate, ICScannerDeviceDelegate, ICDeviceBrowserDelegate 

and you need to have IKScannerDeviceView in your window with its delegate set to a class that implements IKScannerDeviceViewDelegate

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

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

Then we 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 everything is correct, your IKScannerDeviceView will be able to interact with your scanner!

+7
source

Source: https://habr.com/ru/post/1433066/


All Articles