Contents

WKBluetoothAlertRefreshBackgroundTask

A task for handling timely Bluetooth alerts in the background.

Declaration

class WKBluetoothAlertRefreshBackgroundTask

Mentioned in

Overview

Your app can receive WKBluetoothAlertRefreshBackgroundTask tasks to handle timely alerts in the background. Use these tasks to reconnect a peripheral and handle a critical alert. Apps that use timely alerts can also scan for a specific system identifier (UUID) while in the background. You can then perform the initial connection and pair the devices if necessary.

To receive timely alerts, your peripheral must use Generic Attribute Profile (GATT) transactions. Call setNotifyValue(_:for:) to enable notifications for the specified characteristic. Then, any changes to the peripheral’s characteristic wakes your app using a WKBluetoothAlertRefreshBackgroundTask task. Use this task to reconnect to the peripheral and handle the critical alert.

The critical alerts and background scans share a budget. Your app can only use five timely alerts or background scans within a rolling 24-hour window.

When your app receives a timely alert and your budget has only one Bluetooth alert task remaining, the system raises a leGattNearBackgroundNotificationLimit error. If you exceed the budget, it raises a leGattExceededBackgroundNotificationLimit error. The system passes these errors to your CBPeripheralDelegate, by calling methods like the peripheral(_:didUpdateValueFor:error:) method.

If you exceed your budget, your app doesn’t receive any timely alerts until additional background budget becomes available. The user can reset this budget by launching your app.

See Also

Background tasks