我刚开始使用ImageCaptureCore和ICDeviceBrowser来开始开发相机控制软件,它运行正常,但没有找到任何东西。
我已经在包括iPhone在内的3种不同的相机(PTP模式和MSC模式)上进行了尝试。我有最新的MacOS和Xcode。
从不调用委托,并且设备数组始终为空。
import Foundation
import ImageCaptureCore
print("Hello, World!")
let browser = ICDeviceBrowser.init()
let myDeviceBrowserDelegate = myDeviceBrowserDelegateClass.init()
browser.delegate = myDeviceBrowserDelegate
browser.browsedDeviceTypeMask = ICDeviceTypeMask(rawValue: ICDeviceTypeMask.camera.rawValue | ICDeviceLocationTypeMask.local.rawValue | ICDeviceLocationTypeMask.bluetooth.rawValue | ICDeviceLocationTypeMask.bonjour.rawValue | ICDeviceLocationTypeMask.remote.rawValue | ICDeviceLocationTypeMask.shared.rawValue)!
browser.start()
while(browser.isBrowsing){
print("browsing cameras...")
print(browser.devices!)
sleep(10)
}
browser.stop()
这是代表:
import Foundation
import ImageCaptureCore
class myDeviceBrowserDelegateClass : NSObject, ICDeviceBrowserDelegate {
func deviceBrowser(_ browser: ICDeviceBrowser, didAdd device: ICDevice, moreComing: Bool) {
print("Device added = \(device) and more coming = \(moreComing)")
}
func deviceBrowser(_ browser: ICDeviceBrowser, didRemove device: ICDevice, moreGoing: Bool) {
print("Device added = \(device) and more going = \(moreGoing)")
}
}
答案 0 :(得分:0)
问题是我需要执行一个运行循环。由于Xcode工具会自动合并一个runloop,因此我只需要运行它,而不是等待循环
RunLoop.current.run(until: Date.init(timeIntervalSinceNow: 1))