react-native-mytatva-rn-sdk 1.2.62 → 1.2.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -197,6 +197,24 @@
|
|
|
197
197
|
return glucose;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
- (BOOL)hasDeviceData {
|
|
201
|
+
NSManagedObjectContext *context = self.context;
|
|
202
|
+
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Device"];
|
|
203
|
+
|
|
204
|
+
// We're only interested in knowing if there's at least one record
|
|
205
|
+
[fetchRequest setFetchLimit:1];
|
|
206
|
+
|
|
207
|
+
NSError *error = nil;
|
|
208
|
+
NSUInteger count = [context countForFetchRequest:fetchRequest error:&error];
|
|
209
|
+
|
|
210
|
+
if (error) {
|
|
211
|
+
NSLog(@"Error fetching Device data: %@", error.localizedDescription);
|
|
212
|
+
return NO;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return count > 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
200
218
|
// 查询某一张表name
|
|
201
219
|
- (NSArray *)queryTableWithName:(NSString *)name {
|
|
202
220
|
NSEntityDescription *entity = [NSEntityDescription entityForName:name inManagedObjectContext:self.context];
|
|
@@ -127,16 +127,26 @@ import Foundation
|
|
|
127
127
|
|
|
128
128
|
let canConnectOther = KLTLocalSettingManager.shareInstance().canConnectOtherDevice
|
|
129
129
|
let connectedPeripheral = viewModel.manager.connectedPeripheral
|
|
130
|
-
|
|
130
|
+
|
|
131
|
+
|
|
131
132
|
if connectedPeripheral == nil && !canConnectOther {
|
|
132
|
-
viewModel.manager.startScan()
|
|
133
133
|
let bluetoothOff = UserDefaults.standard.bool(forKey: "bluetoothOff")
|
|
134
|
+
// if bluetoothOff {
|
|
135
|
+
// viewModel.debouncer.update(with: .bluetoothOff)
|
|
136
|
+
// }
|
|
137
|
+
|
|
134
138
|
if bluetoothOff == false {
|
|
135
|
-
|
|
139
|
+
let data = KLTDatabaseHandler.shared().hasDeviceData
|
|
140
|
+
if data() {
|
|
141
|
+
viewModel.manager.startScan()
|
|
142
|
+
// viewModel.debouncer.update(with: .transmitterDisconnect)
|
|
143
|
+
} else {
|
|
144
|
+
viewModel.debouncer.update(with: .transmitterDisconnect)
|
|
145
|
+
}
|
|
146
|
+
|
|
136
147
|
} else {
|
|
137
148
|
viewModel.debouncer.update(with: .bluetoothOff)
|
|
138
149
|
}
|
|
139
|
-
|
|
140
150
|
} else {
|
|
141
151
|
if let device = KLTBluetoothManager.shared().currentDevice {
|
|
142
152
|
if device.connectedDateTime == nil && device.disconnectedDateTime == nil {
|
|
@@ -146,7 +156,7 @@ import Foundation
|
|
|
146
156
|
UserDefaults.standard.set(sensorId, forKey: "sensorId")
|
|
147
157
|
UserDefaults.standard.set(patientId, forKey: "patientId")
|
|
148
158
|
}
|
|
149
|
-
} else {
|
|
159
|
+
} else { //when user app unistall and then install
|
|
150
160
|
print("⚠️ currentDevice is nil")
|
|
151
161
|
viewModel.manager.startScan()
|
|
152
162
|
viewModel.debouncer.update(with: .transmitterDisconnect)
|
|
@@ -189,9 +199,17 @@ class FinalViewModel: NSObject {
|
|
|
189
199
|
startCountDown()
|
|
190
200
|
|
|
191
201
|
if ((manager.connectedPeripheral == nil) && !KLTLocalSettingManager.shareInstance().canConnectOtherDevice) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
202
|
+
|
|
203
|
+
let data = KLTDatabaseHandler.shared().hasDeviceData
|
|
204
|
+
if data() {
|
|
205
|
+
manager.startScan()
|
|
206
|
+
// debouncer.update(with: .disconnected)
|
|
207
|
+
print("✅ Device data exists")
|
|
208
|
+
} else{
|
|
209
|
+
debouncer.update(with: .transmitterDisconnect)
|
|
210
|
+
print("❌ Failed to get app delegate or context")
|
|
211
|
+
}
|
|
212
|
+
|
|
195
213
|
} else {
|
|
196
214
|
print("here")
|
|
197
215
|
//debouncer.update(with: .connected)
|
|
@@ -206,6 +224,19 @@ class FinalViewModel: NSObject {
|
|
|
206
224
|
}
|
|
207
225
|
}
|
|
208
226
|
|
|
227
|
+
func isDeviceDataAvailable(context: NSManagedObjectContext) -> Bool {
|
|
228
|
+
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "Device")
|
|
229
|
+
fetchRequest.fetchLimit = 1
|
|
230
|
+
|
|
231
|
+
do {
|
|
232
|
+
let count = try context.count(for: fetchRequest)
|
|
233
|
+
return count > 0
|
|
234
|
+
} catch {
|
|
235
|
+
print("❌ Failed to fetch Device count: \(error.localizedDescription)")
|
|
236
|
+
return false
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
209
240
|
func getStatus(encryptionKey: String = PROD_ENC_KEY,
|
|
210
241
|
encryptionIv: String = PROD_ENC_IV) {
|
|
211
242
|
print("ios token:", TOKEN)
|
|
@@ -389,12 +420,19 @@ class FinalViewModel: NSObject {
|
|
|
389
420
|
let batch = batches[index]
|
|
390
421
|
|
|
391
422
|
// Filter out data where gluADC is 0
|
|
423
|
+
// let filteredBatch = batch.filter {
|
|
424
|
+
// if let gluADC = $0.gluADC as? Int {
|
|
425
|
+
// return gluADC != 0
|
|
426
|
+
// }
|
|
427
|
+
// return false
|
|
428
|
+
// }
|
|
429
|
+
|
|
392
430
|
let filteredBatch = batch.filter {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
return false
|
|
431
|
+
let gluADCValue = ($0.gluADC as? Int) ?? 0
|
|
432
|
+
let isDeleteValue = ($0.isDelete as? Int) ?? 0
|
|
433
|
+
return gluADCValue != 0 && isDeleteValue == 0
|
|
397
434
|
}
|
|
435
|
+
|
|
398
436
|
|
|
399
437
|
let cgmLogs = filteredBatch.map { ReceiveDataToLog(data: $0) }
|
|
400
438
|
let payload = Payload(logs: cgmLogs)
|