# Best Practices

Recommended best practices for Socket Mobile CaptureSDK integration to optimize the end-user experience. Covers monitoring scanner battery levels to prevent downtime during operations, configuring power state change notifications to alert users when a scanner needs charging, and ensuring reliable scanner connectivity. Includes code samples for reading battery level and setting up battery change notifications.

We recommend to use our CaptureSDK so the End Users can use our scanners and readers at their best and providing the best User Experience for them.

For instance, it is important to know the power state of the scanner as it is for the host to make sure it does not need to be recharged during the time the scanner is needed and the operation has a chance to change batteries or charge the scanner.

The application can check the battery level of the scanner using CaptureSDK. Additionally, many Socket Mobile scanners support battery level change notification.

Following are some examples on how to configure the scanner for these features.

## Reading the Battery Level

Here is example code showing how to request the scanner battery level information:

## Swift

```swift
device.getBatteryLevelWithCompletionHandler({ result, batteryLevel in
    if let batteryLevel = batteryLevel {
        let finalBatteryLevel = SKTHelper.getCurrentLevel(fromBatteryLevel: Int(batteryLevel))
        print("Get Battery Level: \(finalBatteryLevel) - Result: \(result.rawValue)")
    }
})
```

## Get Battery Level Change and Power State Notifications

In order to receive the battery level change and power state notifications, you need to subscribe to the [device power events](/docs/using-capturesdk/capture-helper#device-power)

## Swift

```swift
import UIKit
import CaptureSDK

extension MyViewController: UIViewController,
    CaptureHelperDevicePresenceDelegate,
    CaptureHelperDeviceDecodedDataDelegate,
    CaptureHelperDevicePowerDelegate,
    CaptureHelperErrorDelegate {

    ...

    // MARK: - CaptureHelperDevicePowerDelegate

    func didChangeBatteryLevel(_ batteryLevel: Int, forDevice device: CaptureHelperDevice){
        print("Battery level did change: \(SKTHelper.getCurrentLevel(fromBatteryLevel: Int(batteryLevel)))% for device \(String(describing: device.deviceInfo.name!))")
    }

    func didChangePowerState(_ powerState: SKTCapturePowerState, forDevice device: CaptureHelperDevice) {
        print("Receive a power state change \(powerState) for device \(String(describing: device.deviceInfo.name!))")
    }

    ...

}
```