BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

SwiftUI: How can I get the battery level of my AirPods when they are connected?

Forums > SwiftUI

I'm developing a music app and I want to add a feature where the user can see the battery level of their AirPods when they are connected.

I read this article about getting the battery level of an iPhone or iPad but it was not for AirPods and it was UIKit code rather than SwiftUI:


I imagine it would involve working with the Core Bluetooth framework and pinging the AirPods to query information about them.

Here's an article I found on reading characteristics from a Bluetooth device: How to Read BLE Characteristics in Swift | QuickBird Studios Blog

As for SwiftUI vs UIKit, whatever the solution is for reading the battery level, that code would likely go into some kind of service manager that would be accessible to either UI framework. In other words, there isn't really a SwiftUI or a UIKit solution, but rather one that works separately from but in tandem with either.


Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.