|
|
@@ -36,7 +36,6 @@ class HeartBeatManager {
|
|
|
|
|
|
// set to nil, this will force recreation of bluetooth transmitter at app startup
|
|
|
UserDefaults.standard.cgmTransmitterDeviceAddress = nil
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if UserDefaults.standard.cgmTransmitterDeviceAddress != sharedUserDefaults
|
|
|
@@ -46,34 +45,28 @@ class HeartBeatManager {
|
|
|
.deviceManager,
|
|
|
"UserDefaults.standard.cgmTransmitterDeviceAddress != sharedUserDefaults.string(forKey: keyForcgmTransmitterDeviceAddress)"
|
|
|
)
|
|
|
-
|
|
|
- debug(.deviceManager, "UserDefaults.standard.cgmTransmitterDeviceAddress != sharedUserDefaults.string(forKey: keyForcgmTransmitterDeviceAddress)")
|
|
|
if let sharedTransmitterAddress = sharedUserDefaults.string(forKey: keyForcgmTransmitterDeviceAddress) {
|
|
|
debug(.deviceManager, "in checkCGMBluetoothTransmitter, sharedTransmitterAddress = \(sharedTransmitterAddress)")
|
|
|
} else {
|
|
|
debug(.deviceManager, "in checkCGMBluetoothTransmitter, sharedTransmitterAddress = nil")
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// assign local copy of cgmTransmitterDeviceAddress to the value stored in sharedUserDefaults (possibly nil value)
|
|
|
UserDefaults.standard.cgmTransmitterDeviceAddress = sharedUserDefaults
|
|
|
.string(forKey: keyForcgmTransmitterDeviceAddress)
|
|
|
|
|
|
// assign new bluetoothTransmitter. If return value is nil, and if it was not nil before, and if it was currently connected then it will disconnect automatically, because there's no other reference to it, hence deinit will be called
|
|
|
bluetoothTransmitter = setupBluetoothTransmitter(sharedData: sharedUserDefaults)
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private func setupBluetoothTransmitter(sharedData: UserDefaults) -> BluetoothTransmitter? {
|
|
|
-
|
|
|
// if sharedUserDefaults.cgmTransmitterDeviceAddress is not nil then, create a new bluetoothTranmsitter instance
|
|
|
if let cgmTransmitterDeviceAddress = sharedData.string(forKey: keyForcgmTransmitterDeviceAddress) {
|
|
|
-
|
|
|
// unwrap cgmTransmitter_CBUUID_Service and cgmTransmitter_CBUUID_Receive
|
|
|
if let cgmTransmitter_CBUUID_Service = sharedData.string(forKey: keyForcgmTransmitter_CBUUID_Service),
|
|
|
let cgmTransmitter_CBUUID_Receive = sharedData.string(forKey: keycgmTransmitter_CBUUID_Receive)
|
|
|
{
|
|
|
-
|
|
|
// a new cgm transmitter has been setup in xDrip4iOS
|
|
|
// we will connect to the same transmitter here so it can be used as heartbeat
|
|
|
let newBluetoothTransmitter = BluetoothTransmitter(
|