I would like to get all services that contain specific properties.
AppleDeviceManagementHIDEventService <class AppleDeviceManagementHIDEventService, id 0x100000a79, registered, matched, active, busy 0 (0 ms), retain 7>
| | | | | | {
| | | | | | "IOMatchedAtBoot" = Yes
| | | | | | "LowBatteryNotificationPercentage" = 2
| | | | | | "PrimaryUsagePage" = 65280
| | | | | | "BatteryFaultNotificationType" = "TPBatteryFault"
| | | | | | "HasBattery" = Yes
| | | | | | "VendorID" = 76
| | | | | | "VersionNumber" = 0
| | | | | | "Built-In" = No
| | | | | | "DeviceAddress" = "10-94-bb-ab-b9-53"
| | | | | | "WakeReason" = "Host (0x01)"
| | | | | | "Product" = "Magic Trackpad"
| | | | | | "SerialNumber" = "10-94-bb-ab-b9-53"
| | | | | | "Transport" = "Bluetooth"
| | | | | | "BatteryLowNotificationType" = "TPLowBattery"
| | | | | | "ProductID" = 613
| | | | | | "DeviceUsagePairs" = ({"DeviceUsagePage"=65280,"DeviceUsage"=11},{"DeviceUsagePage"=65280,"DeviceUsage"=20})
| | | | | | "IOPersonalityPublisher" = "com.apple.driver.AppleTopCaseHIDEventDriver"
| | | | | | "MTFW Version" = 920
| | | | | | "BD_ADDR" = <1094bbabb953>
| | | | | | "BatteryPercent" = 42
| | | | | | "BatteryStatusNotificationType" = "BatteryStatusChanged"
| | | | | | "CriticallyLowBatteryNotificationPercentage" = 1
| | | | | | "ReportInterval" = 11250
| | | | | | "RadioFW Version" = 368
| | | | | | "VendorIDSource" = 1
| | | | | | "STFW Version" = 2144
| | | | | | "CFBundleIdentifier" = "com.apple.driver.AppleTopCaseHIDEventDriver"
| | | | | | "IOProviderClass" = "IOHIDInterface"
| | | | | | "LocationID" = 1001109843
| | | | | | "BluetoothDevice" = Yes
| | | | | | "IOClass" = "AppleDeviceManagementHIDEventService"
| | | | | | "HIDServiceSupport" = No
| | | | | | "CFBundleIdentifierKernel" = "com.apple.driver.AppleTopCaseHIDEventDriver"
| | | | | | "ProductIDArray" = (613)
| | | | | | "BatteryStatusFlags" = 0
| | | | | | "ColorID" = 5
| | | | | | "IOMatchCategory" = "IODefaultMatchCategory"
| | | | | | "CountryCode" = 0
| | | | | | "IOProbeScore" = 7175
| | | | | | "PrimaryUsage" = 11
| | | | | | "IOGeneralInterest" = "IOCommand is not serializable"
| | | | | | "BTFW Version" = 368
| | | | | | }
Eg. every service that contains the child property "BatteryPercent".
I know that I can get specific service by using IOServiceNameMatching and then IOServiceGetMatchingServices, but this seems to not be working on the properties inside the service. Is it possible to that? I want to match by BatteryPercent and then also get ProductName.
EDIT: This is the code I'm currently using to get the trackpad battery.
func getTrackpadBattery() -> (String, Int) {
var serialPortIterator = io_iterator_t()
var object : io_object_t
var percent: Int = 0
var productName: String = ""
let masterPort: mach_port_t = kIOMainPortDefault
let matchingDict : CFDictionary = IOServiceMatching("AppleDeviceManagementHIDEventService")
let kernResult = IOServiceGetMatchingServices(masterPort, matchingDict, &serialPortIterator)
if KERN_SUCCESS == kernResult {
repeat {
object = IOIteratorNext(serialPortIterator)
if object != 0 {
let percentProperty = IORegistryEntryCreateCFProperty(object, "BatteryPercent" as CFString, kCFAllocatorDefault, 0)
if (percentProperty != nil) {
percent = (percentProperty?.takeRetainedValue() as? Int)!
productName = (IORegistryEntryCreateCFProperty(object, "Product" as CFString, kCFAllocatorDefault, 0).takeRetainedValue() as? String)!
}
}
} while percent == 0
IOObjectRelease(object)
}
IOObjectRelease(serialPortIterator)
return (productName, percent)
}