I have a bluetooth device with a button on it. When the device button is clicked, the notification attribute update and my app show a local notification. It is so simple.
I am connecting a bluetooth device in the foreground as shown below:
var restoreOptions = [CBPeripheralManagerOptionRestoreIdentifierKey: "customIdentifier"] centralManager.connect(peripheral, options: restoreOptions)
Then the set value of the notification flag is true:
peripheral.setNotifyValue(true, for: notificationCharacteristic)
When updating the notification features, the application displays a local notification:
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { showLocalNotification() }
When the notification attribute changes, doUpdateValueFor is started and a local notification is displayed. There are no problems in the foreground and in the background. But when the application is terminated by the user, the bluetooth device is disconnected and didUpdateValueFor does not start. I want to reconnect the Bluetooth device when a characteristic change even the application is terminated by the user. How can i do this? Hope I can tell you about my problem. Thanks.
source share