GCDeviceBattery Charging State

I've been playing around with the GameController framework, and have tried to get the charging state of a controller's battery. However, it doesn't seem to be available in the GCDeviceBattery type.

Does anyone know if getting the charging state is possible? Thanks!

Accepted Reply

Hi,

once you got your controller connected, you can get the battery level like this:

Code Block swift
@objc private func controllerDidConnect(notification: Notification) {
guard let controller = notification.object as? GCController else {
fatalError("Invalid notification object.")
}
var batteryLevel = Float(controller.battery?.batteryLevel ?? 0.0)
}


Replies

Hi,

once you got your controller connected, you can get the battery level like this:

Code Block swift
@objc private func controllerDidConnect(notification: Notification) {
guard let controller = notification.object as? GCController else {
fatalError("Invalid notification object.")
}
var batteryLevel = Float(controller.battery?.batteryLevel ?? 0.0)
}