react-native-mytatva-rn-sdk 1.2.61 → 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) {
@@ -90,6 +90,7 @@
90
90
  case CBManagerStateResetting:
91
91
  case CBManagerStateUnsupported:
92
92
  KLTLog(@"该设备不支持蓝牙,请更换设备");
93
+ [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"bluetoothOff"];
93
94
  [Notification_Center postNotificationName:@"BluetoothEnable" object:@(NO)];
94
95
  break;
95
96
  case CBManagerStateUnauthorized:
@@ -101,10 +102,12 @@
101
102
  self.connectedPeripheral = nil;
102
103
  [self.peripherals removeAllObjects];
103
104
  }
105
+ [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"bluetoothOff"];
104
106
  [Notification_Center postNotificationName:@"BluetoothEnable" object:@(NO)];
105
107
  }
106
108
  break;
107
109
  case CBManagerStatePoweredOn: {
110
+ [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"bluetoothOff"];
108
111
  [Notification_Center postNotificationName:@"BluetoothEnable" object:@(YES)];
109
112
  }
110
113
  break;
@@ -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,14 +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
+
147
+ } else {
148
+ viewModel.debouncer.update(with: .bluetoothOff)
136
149
  }
137
-
138
150
  } else {
139
151
  if let device = KLTBluetoothManager.shared().currentDevice {
140
152
  if device.connectedDateTime == nil && device.disconnectedDateTime == nil {
@@ -144,7 +156,7 @@ import Foundation
144
156
  UserDefaults.standard.set(sensorId, forKey: "sensorId")
145
157
  UserDefaults.standard.set(patientId, forKey: "patientId")
146
158
  }
147
- } else {
159
+ } else { //when user app unistall and then install
148
160
  print("⚠️ currentDevice is nil")
149
161
  viewModel.manager.startScan()
150
162
  viewModel.debouncer.update(with: .transmitterDisconnect)
@@ -187,9 +199,17 @@ class FinalViewModel: NSObject {
187
199
  startCountDown()
188
200
 
189
201
  if ((manager.connectedPeripheral == nil) && !KLTLocalSettingManager.shareInstance().canConnectOtherDevice) {
190
-
191
- manager.startScan()
192
- 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
+
193
213
  } else {
194
214
  print("here")
195
215
  //debouncer.update(with: .connected)
@@ -204,6 +224,19 @@ class FinalViewModel: NSObject {
204
224
  }
205
225
  }
206
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
+
207
240
  func getStatus(encryptionKey: String = PROD_ENC_KEY,
208
241
  encryptionIv: String = PROD_ENC_IV) {
209
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.61",
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",