objc
objc copied to clipboard
Delegating
Hi! I'm trying to find all scan devices using ImageCaptureCore, but the code below doesn't call the delegate's methods. And the similar Objective-C code does. Maybe I'm wrong somewhere because header file(https://github.com/phracker/MacOSX-SDKs/blob/master/MacOSX10.7.sdk/System/Library/Frameworks/ImageCaptureCore.framework/Versions/A/Headers/ICDeviceBrowser.h) is slight different from your example with NSFileManager
const objc = require('../src/index');
const ICDeviceLocationTypeMaskLocal = 0x00000100;
const ICDeviceLocationTypeMaskShared = 0x00000200;
const ICDeviceLocationTypeMaskBonjour = 0x00000400;
const ICDeviceLocationTypeMaskBluetooth = 0x00000800;
const ICDeviceLocationTypeMaskRemote = 0x0000FE00;
const ICDeviceTypeMaskCamera = 0x00000001;
const ICDeviceTypeMaskScanner = 0x00000002;
objc.import('ImageCaptureCore');
const {
ICDeviceBrowser
} = objc;
const DeviceBrowserDelegate = objc.createClass('DeviceBrowserDelegate', 'NSObject', {
"deviceBrowser:didAddDevice:moreComing:": (self, cmd, fileManager, srcPath, dstPath) => {
console.log("deviceBrowser:didAddDevice:moreComing:");
return 1;
},
"deviceBrowser:didRemoveDevice:moreGoing:": (self, cmd, fileManager, srcPath, dstPath) => {
console.log("deviceBrowser:didAddDevice:moreComing:");
return 1;
},
_encodings: {
"deviceBrowser:didAddDevice:moreComing:": ['v', ['@', ':', '@', '@', 'c']],
"deviceBrowser:didRemoveDevice:moreGoing:": ['v', ['@', ':', '@', '@', 'c']]
}
});
const deviceBrowser = ICDeviceBrowser.alloc().init();
const delegate = DeviceBrowserDelegate.new();
deviceBrowser.setDelegate_(delegate);
const mask = ICDeviceTypeMaskScanner | ICDeviceLocationTypeMaskLocal | ICDeviceLocationTypeMaskShared | ICDeviceLocationTypeMaskBonjour | ICDeviceLocationTypeMaskRemote;
deviceBrowser.setBrowsedDeviceTypeMask_(mask);
deviceBrowser.start();
setInterval(() => {
console.log(deviceBrowser.isBrowsing());
}, 2000);
Can you share the working Objective-C version?
Thank for the answer! Sure, I used this example (at that time this project was totally written in Objective-C): https://github.com/klep/scanline/blob/1a65ab3e19c25ea8610b8e445cfce973a2940e7b/scanline/AppController.m#L88 The output is:
Mac-mini-user:Products user$ ./Debug/scanline -list
2019-02-28 16:58:59:688 scanline[696:307] Available scanners:
2019-02-28 16:58:59:690 scanline[696:307] * HP LaserJet Pro MFP M225dw (A87D7F)
I tried to reproduce the issue, but since I don't have any scanners I can't even get the code you linked to get working as expected.
Does this work for you? (basically the objc equivalent of your code)
I'll try it tomorrow. Appreciate a lot for your help!
Yes, I got
browser: <ICDeviceBrowser: 0x100688d80>
-[LKICDeviceBrowserDelegate deviceBrowser:didAddDevice:moreComing:]
in console