可能是一个愚蠢的问题,但我无法弄清楚它是如何工作的。当我在我的IKScannerDeviceView
扫描工作中按下扫描按钮时,它的代表永远不会被调用。我在线上放了一个断点
print("Did scan to: \(url.path)")
扫描文件出现在所选文件夹中没有问题,但它永远不会在断点处停止。我错过了什么吗?只是为了完整起见,我在 macOS 11.0.1 上使用 Xcode 12.2
这是我的代码:
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 ?? "----")
}
}