【发布时间】:2017-01-07 05:07:52
【问题描述】:
有没有一种方法,使用 IOKit 或类似的东西,不涉及从 Internet 下载其他软件包,我可以使用它来读取 USB 设备的产品名称?
这是我当前的代码...
func printSerialPaths(portIterator: io_iterator_t) {
var serialService: io_object_t
repeat {
serialService = IOIteratorNext(portIterator)
if (serialService != 0) {
var key: CFString! = "IOCalloutDevice"
var bsdPathAsCFtring: AnyObject? = IORegistryEntryCreateCFProperty(serialService, key, kCFAllocatorDefault, 0).takeUnretainedValue()
var bsdPath = bsdPathAsCFtring as! String?
if let path = bsdPath {
print(path)
}
var deviceNameCString: [CChar] = [CChar](count: 128, repeatedValue: 0)
let deviceNameResult = IORegistryEntryGetName(serialService, &deviceNameCString)
let deviceName = String.fromCString(&deviceNameCString)!
print("usb Device Name: \(deviceName)")
}
} while serialService != 0;
}
我也尝试过在 IORegistryEntryCreateCFProperty() 命令中使用其他 CFString,例如 "Product Name",正如我在其他地方看到的建议,但没有运气。如果我只需要替换它,我在哪里可以找到其余这些字符串的文档?
我正在谈论的产品名称在下面突出显示。我不确定它的技术名称是什么。
【问题讨论】: