react-native-mytatva-rn-sdk 1.2.62 → 1.2.63

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.
@@ -76,6 +76,9 @@
76
76
  }
77
77
 
78
78
 
79
+
80
+
81
+
79
82
  - (NSManagedObjectContext *)managedObjectContext {
80
83
  // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
81
84
  if (_managedObjectContext != nil) {
@@ -56,4 +56,5 @@
56
56
 
57
57
  - (void)reloadQueryHistoryData;
58
58
  - (void)deleteSQLiteDataArray;
59
+ - (BOOL)hasDeviceData;
59
60
  @end
@@ -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
- viewModel.debouncer.update(with: .transmitterDisconnect)
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
- manager.startScan()
194
- debouncer.update(with: .disconnected)
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-mytatva-rn-sdk",
3
- "version": "1.2.62",
3
+ "version": "1.2.63",
4
4
  "description": "a package to inject data into visit health pwa",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",