How to use IKScannerDeviceView in Cocoa

孤街浪徒 提交于 2020-12-29 07:21:07

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/12326156/how-to-use-ikscannerdeviceview-in-cocoa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!