Battery Status
June 21, 2016

The battery status API retrieves the battery percentage and charging status.

The following code sample reads the battery status from the SCiO device.

__weak typeof(&*self)weakSelf = self;
[[CPScioDevice sharedInstance] getBatteryStatusWithCompletion:^(double percentage, BOOL isCharging, NSError *error) {
    if (error) {
        [weakSelf alertWithTitle:error.userInfo[NSLocalizedDescriptionKey]  message:error.userInfo[NSLocalizedFailureReasonErrorKey]];
        return;
    }
    
    [weakSelf alertWithTitle:@"Battery status" message:[NSString stringWithFormat:@"Status: %@\nPercentage: %.0f", isCharging ? @"Charging" : @"Not charging", percentage]];
}];

Leave a Reply