IKScannerDeviceViewDelegate never called

150 views Asked by At

Probably a dumb question but I cannot figure how make it work. When I press scan button in my IKScannerDeviceView scan works but its delegate never gets called. I put a breakpoint on line

print("Did scan to: \(url.path)")

Scan file appears in selected folder without problems but it never stops on breakpoint. Am I missing something? Just for the sake of completeness I'm using Xcode 12.2 on macOS 11.0.1

Here is my code:


import Cocoa
import ImageCaptureCore
import Quartz

class ViewController: NSViewController {
    @IBOutlet weak var scannerView: IKScannerDeviceView!
    var deviceBrowser:ICDeviceBrowser!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.scannerView.delegate = self
        self.scannerView.mode = .advanced
        self.scannerView.transferMode = .fileBased

        self.deviceBrowser = ICDeviceBrowser()
        self.deviceBrowser.delegate = self
        self.deviceBrowser.browsedDeviceTypeMask = ICDeviceTypeMask(rawValue:
                                                                        ICDeviceLocationTypeMask.local.rawValue |
                                                                        ICDeviceLocationTypeMask.shared.rawValue |
                                                                        ICDeviceLocationTypeMask.bonjour.rawValue |
                                                                        ICDeviceLocationTypeMask.remote.rawValue |
                                                                        ICDeviceLocationTypeMask.bluetooth.rawValue |
                                                                        ICDeviceTypeMask.scanner.rawValue)!
        self.deviceBrowser.start()
    }
}

extension ViewController : IKScannerDeviceViewDelegate {
    func scannerDeviceView(_ scannerDeviceView: IKScannerDeviceView!, didScanTo url: URL!, error: Error!) {
        print("Did scan to: \(url.path)")
    }
}

extension ViewController: ICDeviceBrowserDelegate {
    func deviceBrowser(_ browser: ICDeviceBrowser, didAdd device: ICDevice, moreComing: Bool) {

        if (device.type.rawValue & ICDeviceTypeMask.scanner.rawValue) == ICDeviceType.scanner.rawValue {
            self.scannerView.scannerDevice = (device as! ICScannerDevice)
        }
    }

    func deviceBrowser(_ browser: ICDeviceBrowser, didRemove device: ICDevice, moreGoing: Bool) {
        device.requestCloseSession()
    }

    func didRemoveDevice(device: ICDevice) {
        device.requestCloseSession()
    }

    func device(device: ICDevice, didEncounterError error: NSError?) {
        print("Error")
        print(error?.description ?? "----")
    }
}
1

There are 1 answers

0
Willeke On BEST ANSWER

Apparently the following methods are not called:

func scannerDeviceView(IKScannerDeviceView!, didScanTo: ICScannerBandData!, scanInfo: [AnyHashable : Any]!, error: Error!)
func scannerDeviceView(IKScannerDeviceView!, didScanTo: URL!, error: Error!)

Implement the following method instead:

func scannerDeviceView(IKScannerDeviceView!, didScanTo: URL!, fileData: Data!, error: Error!)