So i’m trying to disconnect from a Bluetooth device upon terminating the app. I have tried using the AppDelegate functions and even subscribing to the NotificiationCeneter with an onReceive method for the willTerminate message, in both instances they fire off and I can see that they’re at the very least being called which is where I have my device.cancelPeripheral… function and whatever is in the functions are attempting to fire. When i go to my Settings, however, I see that my device is still connected.
MyView()
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willTerminateNotification), perform: { output in
print("TERMINATING FROM ONRECEIVE")
guard let device = BTManager.connectedDevice else { return }
BTManager.manager.cancelPeripheralConnection(device.peripheral)
})
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
log("application will terminate")
guard let device = BTManager.connectedDevice else { return }
BTManager.manager.cancelPeripheralConnection(device.peripheral)
}
Does the OS or phone cancel pending functions? I’m curious to find out why this is occurring
2