react-native-mytatva-rn-sdk 1.2.60 → 1.2.62
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.
- package/ios/Database/KLTAppDelegate.h +3 -0
- package/ios/Database/KLTAppDelegate.m +24 -0
- package/ios/Database/KLTBluetoothManager.m +144 -51
- package/ios/Database/KLTDatabaseHandler.h +1 -1
- package/ios/Database/KLTDatabaseHandler.m +18 -13
- package/ios/MyReactNativeBridge.m +25 -22
- package/ios/ViewModel/FinalViewModel.swift +30 -5
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#import <Foundation/Foundation.h>
|
|
11
11
|
#import <CoreData/CoreData.h>
|
|
12
12
|
#import "KLTRunLog.h"
|
|
13
|
+
#import <CoreData/CoreData.h>
|
|
13
14
|
|
|
14
15
|
@interface KLTAppDelegate : NSObject
|
|
15
16
|
|
|
@@ -18,7 +19,9 @@
|
|
|
18
19
|
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
|
|
19
20
|
|
|
20
21
|
- (void)saveContext;
|
|
22
|
+
- (void)deleteAllCoreData;
|
|
21
23
|
- (NSURL *)applicationDocumentsDirectory;
|
|
22
24
|
+ (KLTRunLog *)getCurrentKLTRunLog;
|
|
25
|
+
@property (readonly, strong) NSPersistentContainer *persistentContainer;
|
|
23
26
|
|
|
24
27
|
@end
|
|
@@ -106,4 +106,28 @@
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
- (void)deleteAllCoreData {
|
|
110
|
+
NSPersistentStoreCoordinator *storeCoordinator = self.persistentStoreCoordinator;
|
|
111
|
+
NSManagedObjectContext *context = self.managedObjectContext;
|
|
112
|
+
NSManagedObjectModel *model = storeCoordinator.managedObjectModel;
|
|
113
|
+
|
|
114
|
+
for (NSEntityDescription *entity in model.entities) {
|
|
115
|
+
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:entity.name];
|
|
116
|
+
|
|
117
|
+
NSBatchDeleteRequest *deleteRequest = [[NSBatchDeleteRequest alloc] initWithFetchRequest:fetchRequest];
|
|
118
|
+
|
|
119
|
+
NSError *deleteError = nil;
|
|
120
|
+
[storeCoordinator executeRequest:deleteRequest withContext:context error:&deleteError];
|
|
121
|
+
|
|
122
|
+
if (deleteError) {
|
|
123
|
+
NSLog(@"Failed to delete entity %@: %@", entity.name, deleteError.localizedDescription);
|
|
124
|
+
} else {
|
|
125
|
+
NSLog(@"Successfully deleted entity %@", entity.name);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
[self saveContext];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
109
133
|
@end
|
|
@@ -62,6 +62,9 @@
|
|
|
62
62
|
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
|
|
63
63
|
self.peripherals = [NSMutableArray array];
|
|
64
64
|
self.status = BluetoothManagerStatusInitial;
|
|
65
|
+
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self
|
|
66
|
+
queue:dispatch_get_main_queue()
|
|
67
|
+
options:@{CBCentralManagerOptionRestoreIdentifierKey: @"com.drstore.bluetooth.central"}];
|
|
65
68
|
self.isInResend = NO;
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -87,6 +90,7 @@
|
|
|
87
90
|
case CBManagerStateResetting:
|
|
88
91
|
case CBManagerStateUnsupported:
|
|
89
92
|
KLTLog(@"该设备不支持蓝牙,请更换设备");
|
|
93
|
+
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"bluetoothOff"];
|
|
90
94
|
[Notification_Center postNotificationName:@"BluetoothEnable" object:@(NO)];
|
|
91
95
|
break;
|
|
92
96
|
case CBManagerStateUnauthorized:
|
|
@@ -98,10 +102,12 @@
|
|
|
98
102
|
self.connectedPeripheral = nil;
|
|
99
103
|
[self.peripherals removeAllObjects];
|
|
100
104
|
}
|
|
105
|
+
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"bluetoothOff"];
|
|
101
106
|
[Notification_Center postNotificationName:@"BluetoothEnable" object:@(NO)];
|
|
102
107
|
}
|
|
103
108
|
break;
|
|
104
109
|
case CBManagerStatePoweredOn: {
|
|
110
|
+
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"bluetoothOff"];
|
|
105
111
|
[Notification_Center postNotificationName:@"BluetoothEnable" object:@(YES)];
|
|
106
112
|
}
|
|
107
113
|
break;
|
|
@@ -181,32 +187,37 @@
|
|
|
181
187
|
}
|
|
182
188
|
|
|
183
189
|
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
|
|
184
|
-
|
|
190
|
+
NSLog(@"%s", __FUNCTION__);
|
|
185
191
|
self.bgConnectPeripheral = peripheral;
|
|
192
|
+
|
|
193
|
+
[[KLTDatabaseHandler shared] updateDeviceWithDeviceId:[self.connectedPeripheral.identifier UUIDString]
|
|
194
|
+
scannedTime:nil
|
|
195
|
+
connectTime:nil
|
|
196
|
+
disConnectTime:[NSString getWholeStringWithDate:NSDate.date]];
|
|
186
197
|
|
|
187
|
-
[[KLTDatabaseHandler shared] updateDeviceWithDeviceId:[self.connectedPeripheral.identifier UUIDString] scannedTime:nil connectTime:nil disConnectTime:[NSString getWholeStringWithDate:NSDate.date]];
|
|
188
198
|
self.connectedPeripheral = nil;
|
|
189
199
|
self.status = BluetoothManagerStatusDisconnected;
|
|
190
|
-
|
|
191
|
-
if (
|
|
192
|
-
if (!
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
|
|
201
|
+
if (!KLTLocalSettingManager.shareInstance.canConnectOtherDevice) {
|
|
202
|
+
if (!self.isBgForceConnectDevice) {
|
|
203
|
+
[self connectPeripheral:peripheral];
|
|
204
|
+
self.isBgForceConnectDevice = YES;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (!_rescanTimer) {
|
|
208
|
+
[_rescanTimer invalidate];
|
|
209
|
+
_rescanTimer = nil;
|
|
210
|
+
_rescanTimer = [NSTimer scheduledTimerWithTimeInterval:30
|
|
211
|
+
target:self
|
|
212
|
+
selector:@selector(startScan)
|
|
213
|
+
userInfo:nil
|
|
214
|
+
repeats:YES];
|
|
204
215
|
}
|
|
205
216
|
} else {
|
|
206
217
|
self.isBgForceConnectDevice = NO;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
218
|
+
|
|
219
|
+
[self.peripherals removeObject:peripheral];
|
|
220
|
+
|
|
210
221
|
if ([self.bluetoothDelegate respondsToSelector:@selector(onFindDevices:connectedDevice:)]) {
|
|
211
222
|
[self.bluetoothDelegate onFindDevices:_peripherals connectedDevice:nil];
|
|
212
223
|
}
|
|
@@ -624,46 +635,69 @@
|
|
|
624
635
|
}
|
|
625
636
|
|
|
626
637
|
// 开始扫描
|
|
638
|
+
//- (void)startScan {
|
|
639
|
+
// self.connectedPeripheral = nil;
|
|
640
|
+
// [self.peripherals removeAllObjects];
|
|
641
|
+
//
|
|
642
|
+
// if (self.centralManager.state != CBManagerStatePoweredOn) {
|
|
643
|
+
// return;
|
|
644
|
+
// }
|
|
645
|
+
// KLTLog(@"Allen manager start scan %d", __LINE__);
|
|
646
|
+
//
|
|
647
|
+
// if ([[User_Defaults objectForKey:@"bgmode"] intValue] == 1) {
|
|
648
|
+
// self.status = BluetoothManagerStatusDisconnected;
|
|
649
|
+
//
|
|
650
|
+
// [[KLTDatabaseHandler shared] updateDeviceWithDeviceId:[self.bgConnectPeripheral.identifier UUIDString] scannedTime:nil connectTime:nil disConnectTime:[KLTFormat getDateString]];
|
|
651
|
+
// self.connectedPeripheral = nil;
|
|
652
|
+
//
|
|
653
|
+
// if (!KLTLocalSettingManager.shareInstance.canConnectOtherDevice) {
|
|
654
|
+
// /* 如果当前周期还没结束且处于后台,则强制连接发射器 */
|
|
655
|
+
// if (!self.isBgForceConnectDevice) {
|
|
656
|
+
// [self connectPeripheral:self.bgConnectPeripheral];
|
|
657
|
+
// self.isBgForceConnectDevice = YES;
|
|
658
|
+
// }
|
|
659
|
+
//
|
|
660
|
+
// if (!_rescanTimer) {
|
|
661
|
+
// [_rescanTimer invalidate];
|
|
662
|
+
// _rescanTimer = nil;
|
|
663
|
+
// _rescanTimer = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(startScan) userInfo:nil repeats:YES];
|
|
664
|
+
// }
|
|
665
|
+
// }
|
|
666
|
+
// return;
|
|
667
|
+
// }
|
|
668
|
+
//
|
|
669
|
+
// self.isBgForceConnectDevice = NO;
|
|
670
|
+
// self.status = BluetoothManagerStatusScanStart;
|
|
671
|
+
// // 如果用特定的UUID传参可能找不到任何设备
|
|
672
|
+
// // [self.centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:SERVICE_UUID]] options:nil];
|
|
673
|
+
// // 扫描多台外设
|
|
674
|
+
// NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
|
|
675
|
+
// [self.centralManager scanForPeripheralsWithServices:nil options:scanOptions];
|
|
676
|
+
// // 用定时器来监控扫描超时的情况、监控扫描时间的定时器
|
|
677
|
+
// _connectTimer = [NSTimer scheduledTimerWithTimeInterval:20.f target:self selector:@selector(endScan) userInfo:nil repeats:NO];
|
|
678
|
+
//}
|
|
679
|
+
|
|
627
680
|
- (void)startScan {
|
|
628
681
|
self.connectedPeripheral = nil;
|
|
629
682
|
[self.peripherals removeAllObjects];
|
|
630
|
-
|
|
683
|
+
|
|
631
684
|
if (self.centralManager.state != CBManagerStatePoweredOn) {
|
|
685
|
+
NSLog(@"Bluetooth is not powered on. Aborting scan.");
|
|
632
686
|
return;
|
|
633
687
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if ([[User_Defaults objectForKey:@"bgmode"] intValue] == 1) {
|
|
637
|
-
self.status = BluetoothManagerStatusDisconnected;
|
|
638
|
-
|
|
639
|
-
[[KLTDatabaseHandler shared] updateDeviceWithDeviceId:[self.bgConnectPeripheral.identifier UUIDString] scannedTime:nil connectTime:nil disConnectTime:[KLTFormat getDateString]];
|
|
640
|
-
self.connectedPeripheral = nil;
|
|
641
|
-
|
|
642
|
-
if (!KLTLocalSettingManager.shareInstance.canConnectOtherDevice) {
|
|
643
|
-
/* 如果当前周期还没结束且处于后台,则强制连接发射器 */
|
|
644
|
-
if (!self.isBgForceConnectDevice) {
|
|
645
|
-
[self connectPeripheral:self.bgConnectPeripheral];
|
|
646
|
-
self.isBgForceConnectDevice = YES;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
if (!_rescanTimer) {
|
|
650
|
-
[_rescanTimer invalidate];
|
|
651
|
-
_rescanTimer = nil;
|
|
652
|
-
_rescanTimer = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(startScan) userInfo:nil repeats:YES];
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
self.isBgForceConnectDevice = NO;
|
|
688
|
+
|
|
689
|
+
NSLog(@"Allen manager start scan %d", __LINE__);
|
|
659
690
|
self.status = BluetoothManagerStatusScanStart;
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
|
|
691
|
+
self.isBgForceConnectDevice = NO;
|
|
692
|
+
|
|
693
|
+
NSDictionary *scanOptions = @{ CBCentralManagerScanOptionAllowDuplicatesKey: @(YES) };
|
|
664
694
|
[self.centralManager scanForPeripheralsWithServices:nil options:scanOptions];
|
|
665
|
-
|
|
666
|
-
_connectTimer = [NSTimer scheduledTimerWithTimeInterval:20.
|
|
695
|
+
|
|
696
|
+
_connectTimer = [NSTimer scheduledTimerWithTimeInterval:20.0
|
|
697
|
+
target:self
|
|
698
|
+
selector:@selector(endScan)
|
|
699
|
+
userInfo:nil
|
|
700
|
+
repeats:NO];
|
|
667
701
|
}
|
|
668
702
|
|
|
669
703
|
// 断开与外设的连接,取消对characteristic的监听
|
|
@@ -736,4 +770,63 @@
|
|
|
736
770
|
return _currentDevice;
|
|
737
771
|
}
|
|
738
772
|
|
|
773
|
+
- (void)setStatus:(BluetoothManagerStatus)newStatus {
|
|
774
|
+
_status = newStatus;
|
|
775
|
+
|
|
776
|
+
// Notify observers
|
|
777
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:@"BLEStatusUpdated" object:@(newStatus)];
|
|
778
|
+
|
|
779
|
+
// Print with foreground/background context
|
|
780
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
781
|
+
[self logBluetoothStatus:newStatus];
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
- (void)logBluetoothStatus:(BluetoothManagerStatus)status {
|
|
786
|
+
NSString *stateString = UIApplication.sharedApplication.applicationState == UIApplicationStateBackground ? @"Background" : @"Foreground";
|
|
787
|
+
NSLog(@"[BLE] App is in %@ — Status Code******: %ld", stateString, (long)status);
|
|
788
|
+
}
|
|
789
|
+
- (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary<NSString *,id> *)dict {
|
|
790
|
+
NSLog(@" [RestoreState] iOS triggered state restoration");
|
|
791
|
+
|
|
792
|
+
NSArray *peripherals = dict[CBCentralManagerRestoredStatePeripheralsKey];
|
|
793
|
+
for (CBPeripheral *peripheral in peripherals) {
|
|
794
|
+
if (!peripheral.identifier) {
|
|
795
|
+
NSLog(@" Skipping peripheral: missing identifier");
|
|
796
|
+
continue;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
NSString *peripheralId = peripheral.identifier.UUIDString;
|
|
800
|
+
NSLog(@" Restoring peripheral: %@", peripheralId);
|
|
801
|
+
|
|
802
|
+
self.connectedPeripheral = peripheral;
|
|
803
|
+
self.connectedPeripheral.delegate = self;
|
|
804
|
+
|
|
805
|
+
Device *device = [[KLTDatabaseHandler shared] queryDeviceWithId:peripheralId];
|
|
806
|
+
if (!device || !device.advertise || !device.advertise.localName) {
|
|
807
|
+
NSLog(@"No valid device info found in DB for %@", peripheralId);
|
|
808
|
+
continue;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
self.eDevice = [EDevice getEnumDevice:device.advertise.localName];
|
|
812
|
+
if (!self.eDevice || !self.eDevice.eGattMessage || !self.eDevice.eGattMessage.UUID_SERVICE) {
|
|
813
|
+
NSLog(@" Invalid eDevice config. Cannot reconnect.");
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
NSLog(@"Attempting reconnect...");
|
|
818
|
+
[self.centralManager connectPeripheral:peripheral options:nil];
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
NSArray *scanServices = dict[CBCentralManagerRestoredStateScanServicesKey];
|
|
822
|
+
NSDictionary *scanOptions = dict[CBCentralManagerRestoredStateScanOptionsKey];
|
|
823
|
+
|
|
824
|
+
if (scanServices.count > 0) {
|
|
825
|
+
NSLog(@" Restored scan services: %@", scanServices);
|
|
826
|
+
}
|
|
827
|
+
if (scanOptions) {
|
|
828
|
+
NSLog(@"Restored scan options: %@", scanOptions);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
739
832
|
@end
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
|
|
49
49
|
LatestData *d = [[LatestData alloc] initWithParameters:[data.glucoseId intValue] andIw:[data.operatingCurrent floatValue] andIb:[data.blankCurrent floatValue] andT:[data.temperature floatValue] andK0:algo_k andR:algo_r andDay:(int)[comp day] andHour:(int)[comp hour] andMinute:(int)[comp minute] andName:localName];
|
|
50
50
|
d.algorithm = AlgorithmType_CT4;
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
KLTLog(@"算法入参dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, algorithm=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.algorithm));
|
|
53
53
|
CurrentGlucose *currentGlucose = [AlgorithmTools algorithmLatestGlucose:d];
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
/* data.glu 保存 ADC 算法结果 单位mmol/L */
|
|
56
56
|
/* data.gluADC 保存 凯立特 算法结果 单位mg/dL */
|
|
57
57
|
data.glu = @(currentGlucose.GluMG/18.0);
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
data.countdownHours = @(currentGlucose.countdownHours);
|
|
64
64
|
data.countdownMinutes = @(currentGlucose.countdownMinutes);
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
// [Notification_Center postNotificationName:@"ErrorStatusFromTransmitter" object:data];
|
|
67
67
|
[self.appDelegate saveContext];
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
ReceiveData *receive = [NSEntityDescription insertNewObjectForEntityForName:@"ReceiveDataInfo" inManagedObjectContext:self.context];
|
|
73
73
|
receive.userBG = currentDevice.userBG;
|
|
74
74
|
receive.initialBeginDate = currentDevice.initialBeginDate;
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
[self.appDelegate saveContext];
|
|
77
77
|
return receive;
|
|
78
78
|
}
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
glucose.temperature = data.temperature;
|
|
134
134
|
float algo_k = [[User_Defaults objectForKey:@"algo_k"] floatValue];
|
|
135
135
|
float algo_r = [[User_Defaults objectForKey:@"algo_r"] floatValue];
|
|
136
|
-
|
|
136
|
+
|
|
137
137
|
LatestData *d = nil;
|
|
138
138
|
NSString *localName = data.device.advertise.localName;
|
|
139
139
|
int userBG = roundf(glucose.userBG.floatValue * 18);
|
|
@@ -143,7 +143,7 @@
|
|
|
143
143
|
d = [[LatestData alloc] initWithParameters:([glucose.dataId intValue]) andIw:[glucose.operatingCurrent floatValue] andIb:[glucose.blankCurrent floatValue] andT:[glucose.temperature floatValue] andK0:algo_k andR:algo_r andDay:[data.day intValue] andHour:[data.hour intValue] andMinute:[data.minute intValue] andName:localName];
|
|
144
144
|
}
|
|
145
145
|
d.algorithm = AlgorithmType_CT4;
|
|
146
|
-
|
|
146
|
+
|
|
147
147
|
KLTLog(@"算法入参dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, newBgValue=%@, algorithm=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.newBgValue), @(d.algorithm));
|
|
148
148
|
CurrentGlucose *currentGlucose = [AlgorithmTools algorithmLatestGlucose:d];
|
|
149
149
|
|
|
@@ -156,11 +156,11 @@
|
|
|
156
156
|
d = [[LatestData alloc] initWithParameters:([glucose.dataId intValue]) andIw:[glucose.operatingCurrent floatValue] andIb:[glucose.blankCurrent floatValue] andT:[glucose.temperature floatValue] andK0:algo_k andR:algo_r andDay:[data.day intValue] andHour:[data.hour intValue] andMinute:[data.minute intValue] andName:localName];
|
|
157
157
|
}
|
|
158
158
|
d.algorithm = AlgorithmType_CT4;
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
KLTLog(@"ERROR_CODE_ALGORITHM_DATA:dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, newBgValue=%@, algorithm=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.newBgValue), @(d.algorithm));
|
|
161
161
|
currentGlucose = [AlgorithmTools algorithmLatestGlucose:d];
|
|
162
162
|
}
|
|
163
|
-
|
|
163
|
+
|
|
164
164
|
glucose.errorCode = @(currentGlucose.errorCode);
|
|
165
165
|
glucose.trend = @(currentGlucose.trend);
|
|
166
166
|
/* glucose.glu 保存 ADC 算法结果 单位mmol */
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
glucose.gluADC = @(currentGlucose.GluMG);
|
|
170
170
|
// 标识下次能不能再输入校准参比
|
|
171
171
|
glucose.calibrationStatus = @(currentGlucose.calibrationStatus);
|
|
172
|
-
|
|
172
|
+
|
|
173
173
|
data.glu = @(currentGlucose.GluMG/18.0);
|
|
174
174
|
data.gluADC = @(currentGlucose.GluMG);
|
|
175
175
|
data.calibration = @(currentGlucose.BGMG);
|
|
@@ -190,7 +190,7 @@
|
|
|
190
190
|
glucose.hour = data.hour;
|
|
191
191
|
glucose.error = data.error;
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
// [Notification_Center postNotificationName:@"ErrorStatusFromTransmitter" object: glucose];
|
|
194
194
|
[Notification_Center postNotificationName:@"CheckErrorStatusFromLastBatchData" object: glucose];
|
|
195
195
|
|
|
196
196
|
[self.appDelegate saveContext];
|
|
@@ -227,7 +227,7 @@
|
|
|
227
227
|
|
|
228
228
|
NSArray *resendDatas = [self.context executeFetchRequest:request error:nil];
|
|
229
229
|
resendDatas = [resendDatas sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"receiveDateTime" ascending:YES]]];
|
|
230
|
-
|
|
230
|
+
|
|
231
231
|
// 🖨️ Add single-line logging for each GlucoseData entry
|
|
232
232
|
NSLog(@"==== GlucoseData (Fetched %lu records) for Device: %@ ====", (unsigned long)resendDatas.count, currentDevice.identifier);
|
|
233
233
|
for (GlucoseData *g in resendDatas) {
|
|
@@ -247,9 +247,9 @@
|
|
|
247
247
|
g.countdownHours,
|
|
248
248
|
g.countdownDays
|
|
249
249
|
|
|
250
|
-
|
|
250
|
+
);
|
|
251
251
|
}
|
|
252
|
-
|
|
252
|
+
|
|
253
253
|
return resendDatas;
|
|
254
254
|
}
|
|
255
255
|
|
|
@@ -288,6 +288,11 @@
|
|
|
288
288
|
|
|
289
289
|
[self.appDelegate saveContext];
|
|
290
290
|
}
|
|
291
|
+
|
|
292
|
+
- (void)deleteSQLiteDataArray {
|
|
293
|
+
[self.appDelegate deleteAllCoreData];
|
|
294
|
+
}
|
|
295
|
+
|
|
291
296
|
- (void)deleteReceiveDataArray:(NSArray *)dataArray {
|
|
292
297
|
|
|
293
298
|
for (NSManagedObject *record in dataArray) {
|
|
@@ -203,6 +203,7 @@
|
|
|
203
203
|
#import <React/RCTBridgeModule.h>
|
|
204
204
|
#import <React/RCTEventEmitter.h>
|
|
205
205
|
#import "react_native_mytatva_rn_sdk-Swift.h"
|
|
206
|
+
#import "KLTDatabaseHandler.h"
|
|
206
207
|
|
|
207
208
|
@implementation MyEventEmitterManager
|
|
208
209
|
|
|
@@ -455,9 +456,9 @@ RCT_EXPORT_METHOD(startCgmTracky:(NSString *)token envType: (NSString *)envType
|
|
|
455
456
|
|
|
456
457
|
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:nativeVC];
|
|
457
458
|
navController.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
459
|
+
if (nativeVC) {
|
|
460
|
+
[rootVC presentViewController:navController animated:YES completion:nil];
|
|
461
|
+
}
|
|
461
462
|
});
|
|
462
463
|
}
|
|
463
464
|
|
|
@@ -513,28 +514,32 @@ RCT_EXPORT_METHOD(openHelpSupport)
|
|
|
513
514
|
|
|
514
515
|
RCT_EXPORT_METHOD(observeAllGlucoseData:(NSString *)token isForClearData:(BOOL)isForClearData envType:(NSString *)envType)
|
|
515
516
|
{
|
|
517
|
+
if (isForClearData == YES) {
|
|
518
|
+
[[KLTDatabaseHandler shared].appDelegate deleteAllCoreData];
|
|
519
|
+
}
|
|
520
|
+
|
|
516
521
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
517
522
|
[defaults setObject:token forKey:@"authToken"];
|
|
518
523
|
[defaults setObject:envType forKey:@"envType"];
|
|
519
|
-
|
|
524
|
+
[defaults synchronize];
|
|
520
525
|
|
|
521
526
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
527
|
+
UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
|
|
528
|
+
UIViewController *rootVC = keyWindow.rootViewController;
|
|
529
|
+
|
|
530
|
+
// Load the storyboard
|
|
531
|
+
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainCGM" bundle:nil];
|
|
532
|
+
|
|
533
|
+
// Instantiate the target ViewController
|
|
534
|
+
globalAttachTransmitterVC = [storyboard instantiateViewControllerWithIdentifier:@"AttachTransmitterViewController"];
|
|
535
|
+
|
|
536
|
+
// Set presentation style
|
|
537
|
+
// chatWithExpertVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
538
|
+
|
|
539
|
+
// Present it directly without navigation
|
|
540
|
+
//if (chatWithExpertVC) {
|
|
541
|
+
// [rootVC presentViewController:chatWithExpertVC animated:YES completion:nil];
|
|
542
|
+
// }
|
|
538
543
|
});
|
|
539
544
|
}
|
|
540
545
|
|
|
@@ -581,6 +586,4 @@ RCT_EXPORT_METHOD(observeTransmitterUnbindStatus:(NSString *)token
|
|
|
581
586
|
}];
|
|
582
587
|
}
|
|
583
588
|
|
|
584
|
-
|
|
585
|
-
|
|
586
589
|
@end
|
|
@@ -114,7 +114,14 @@ import Foundation
|
|
|
114
114
|
patientId: String
|
|
115
115
|
) -> [String: Any] {
|
|
116
116
|
let updatedResponse = response
|
|
117
|
-
|
|
117
|
+
let lastSensorId = UserDefaults.standard.string(forKey: "sensorId") ?? ""
|
|
118
|
+
let lastPatientId = UserDefaults.standard.string(forKey: "patientId") ?? ""
|
|
119
|
+
|
|
120
|
+
if (lastPatientId != "" && lastSensorId != "" && (lastPatientId != patientId || lastSensorId != sensorId)) {
|
|
121
|
+
KLTDatabaseHandler.shared().deleteSQLiteDataArray()
|
|
122
|
+
return [:]
|
|
123
|
+
}
|
|
124
|
+
|
|
118
125
|
if viewModel.isCurrentDateInRange(startDate: startDate, endDate: endDate) {
|
|
119
126
|
print("Current date is in range")
|
|
120
127
|
|
|
@@ -123,7 +130,13 @@ import Foundation
|
|
|
123
130
|
|
|
124
131
|
if connectedPeripheral == nil && !canConnectOther {
|
|
125
132
|
viewModel.manager.startScan()
|
|
126
|
-
|
|
133
|
+
let bluetoothOff = UserDefaults.standard.bool(forKey: "bluetoothOff")
|
|
134
|
+
if bluetoothOff == false {
|
|
135
|
+
viewModel.debouncer.update(with: .transmitterDisconnect)
|
|
136
|
+
} else {
|
|
137
|
+
viewModel.debouncer.update(with: .bluetoothOff)
|
|
138
|
+
}
|
|
139
|
+
|
|
127
140
|
} else {
|
|
128
141
|
if let device = KLTBluetoothManager.shared().currentDevice {
|
|
129
142
|
if device.connectedDateTime == nil && device.disconnectedDateTime == nil {
|
|
@@ -315,12 +328,21 @@ class FinalViewModel: NSObject {
|
|
|
315
328
|
|
|
316
329
|
addAllObservers()
|
|
317
330
|
}
|
|
318
|
-
|
|
331
|
+
|
|
332
|
+
@objc func onBLEStatusUpdate(_ notification: Notification) {
|
|
333
|
+
if let statusNumber = notification.object as? NSNumber {
|
|
334
|
+
let status = statusNumber.intValue
|
|
335
|
+
print("[UI] BLE status********: \(status)")
|
|
336
|
+
// update UI or call startScan again
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
319
340
|
func addAllObservers() {
|
|
320
341
|
manager.addObserver(self, forKeyPath: "status", options: .new, context: nil)
|
|
321
342
|
|
|
322
343
|
NotificationCenter.default.addObserver(self, selector: #selector(bluetoothEnable(_:)), name: NSNotification.Name("BluetoothEnable"), object: nil)
|
|
323
|
-
|
|
344
|
+
NotificationCenter.default.addObserver(self, selector: #selector(onBLEStatusUpdate(_:)), name: NSNotification.Name("BLEStatusUpdated"), object: nil)
|
|
345
|
+
|
|
324
346
|
// NotificationCenter.default.addObserver(self, selector: #selector(errorStatusFromTransmitter(_:)), name: NSNotification.Name("ErrorStatusFromTransmitter"), object: nil)
|
|
325
347
|
|
|
326
348
|
NotificationCenter.default.addObserver(self, selector: #selector(handleLatestReceiveData(_:)), name: NSNotification.Name(KLTAlertCurrentInInitialNotify), object: nil)
|
|
@@ -518,8 +540,11 @@ class FinalViewModel: NSObject {
|
|
|
518
540
|
@objc func bluetoothEnable(_ notification: Notification) {
|
|
519
541
|
if let isBluetoothEnabled = notification.object as? Bool {
|
|
520
542
|
if !isBluetoothEnabled {
|
|
543
|
+
UserDefaults.standard.set(true, forKey: "bluetoothOff")
|
|
521
544
|
debouncer.update(with: CGMConnectionStatus.bluetoothOff)
|
|
522
545
|
//API.shared.sendStatus(status: .bluetoothOff)
|
|
546
|
+
} else {
|
|
547
|
+
UserDefaults.standard.set(false, forKey: "bluetoothOff")
|
|
523
548
|
}
|
|
524
549
|
}
|
|
525
550
|
if ((manager.connectedPeripheral == nil) && !KLTLocalSettingManager.shareInstance().canConnectOtherDevice) {
|
|
@@ -602,7 +627,7 @@ class FinalViewModel: NSObject {
|
|
|
602
627
|
|
|
603
628
|
if KLTLocalSettingManager.shareInstance().canConnectOtherDevice {
|
|
604
629
|
endBleSensorCycle()
|
|
605
|
-
} else if UserDefaults.standard.integer(forKey: "bgmode") != 1
|
|
630
|
+
} else {//if UserDefaults.standard.integer(forKey: "bgmode") != 1
|
|
606
631
|
manager.startScan()
|
|
607
632
|
}
|
|
608
633
|
|