macOS Battery Level for Apple Powerbeats Pro

I am working on a macOS app for monitoring battery levels of BlueTooth devices. All of the Apple devices I can get via ioReg and all of the BTLe devices I can use 180F and 2A19, but the Powerbeats Pro has no ioReg I could find and although CoreBluetooth sees the devices, when I query for the peripheral’s services I get back an empty response.

As Apple displays the battery level information in both the Bluetooth app in System Prefs, as well as the accompanying menu bar app, and on iOS devices, there must be a way to obtain this information. All I want to do is retrieve and monitor it so I can display the current battery level.

Here’s an overview of the CoreBluetooth portion of my App Delegate. I realize this is not my complete App Delegate but this is the complete CoreBluetooth portion I can post.

func centralManagerDidUpdateState(_ central: CBCentralManager) {
        if central.state == .poweredOn {
            central.scanForPeripherals(withServices: nil, options: nil)
        } else {
            print("Bluetooth is not available.")
        }
        if let centralManager {
            DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
                centralManager.stopScan()
            }
        }
    }

    func centralManager(
        _ central: CBCentralManager,
        didDiscover peripheral: CBPeripheral,
        advertisementData: [String : Any],
        rssi RSSI: NSNumber
    ) {

        if !self.btDevicesBTLe.contains(where: {
            $0.deviceUUID == peripheral.identifier.uuidString
        }) {

            if let deviceName = peripheral.name {

                let device = BTDevice(
                    deviceUUID: peripheral.identifier.uuidString,
                    deviceConnected: false,
                    deviceMACAddress: nil,
                    deviceName: deviceName,
                    hasBattery: false,
                    batteryLow: false,
                    batteryPercent: ""
                )

                self.btDevicesBTLe.append(device)

            }

            discoveredPeripherals[peripheral.identifier] = peripheral

        }
        if let centralManager {
            centralManager.connect(peripheral, options: nil)
        }

    }

    func centralManager(
        _ central: CBCentralManager,
        didConnect peripheral: CBPeripheral
    ) {
        if let index = btDevicesBTLe.firstIndex(where: {
            $0.deviceName == peripheral.name
        }) {
            btDevicesBTLe[index].deviceConnected = true
        }
        peripheral.delegate = self
        peripheral.discoverServices(nil)
    }

    func peripheral(
        _ peripheral: CBPeripheral,
        didDiscoverServices error: Error?
    ) {

        if let services = peripheral.services {
            for service in services {

                if service.uuid == CBUUID(string: "180F") {
                    peripheral.discoverCharacteristics(nil, for: service)

                    if let deviceIndex = self.btDevicesBTLe.firstIndex(where: {
                        $0.deviceName == peripheral.name
                    }) {
                        self.btDevicesBTLe[deviceIndex].hasBattery = true
                    }
                } else {
                    self.btDevicesBTLe.removeAll {
                        $0.deviceName == peripheral.name
                    }
                }
            }
        }
    }

    func peripheral(
        _ peripheral: CBPeripheral,
        didDiscoverCharacteristicsFor service: CBService,
        error: Error?
    ) {
        if let characteristics = service.characteristics {
            for characteristic in characteristics {
                if characteristic.uuid == CBUUID(string: "2A19") {
                    peripheral.setNotifyValue(true, for: characteristic)
                    peripheral.readValue(for: characteristic)
                }
            }
        }
    }

    func peripheral(
        _ peripheral: CBPeripheral,
        didUpdateValueFor characteristic: CBCharacteristic,
        error: Error?
    ) {
        if characteristic.uuid == CBUUID(string: "2A19") {
            if let value = characteristic.value {
                let valueUint8 = [UInt8](value)
                let batteryLevel: Int32 = Int32(bitPattern: UInt32(valueUint8[0]))

                if let index = self.btDevicesBTLe.firstIndex(where: {
                    $0.deviceName == peripheral.name
                }) {
                    btDevicesBTLe[index].batteryPercent = "(batteryLevel)"
                }
            }
        }
    }

    func centralManager(
        _ central: CBCentralManager,
        didDisconnectPeripheral peripheral: CBPeripheral,
        error: Error?
    ) {
        if central.state == .poweredOn {
            central.scanForPeripherals(withServices: nil, options: nil)
        } else {
            print("Bluetooth is not available.")
        }

        if let centralManager {
            DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
                centralManager.stopScan()
            }
        }
    }

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật