diff options
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP7Module.m')
| -rw-r--r-- | libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP7Module.m | 521 |
1 files changed, 521 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP7Module.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP7Module.m new file mode 100644 index 0000000..7745c0c --- /dev/null +++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP7Module.m | |||
| @@ -0,0 +1,521 @@ | |||
| 1 | // | ||
| 2 | // BP7Module.m | ||
| 3 | // ReactNativeIOSLibrary | ||
| 4 | // | ||
| 5 | // Created by daiqingquan on 2016/11/23. | ||
| 6 | // Copyright © 2016年 daiqingquan. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "BP7Module.h" | ||
| 10 | #import "BPProfileModule.h" | ||
| 11 | #import "BPMacroFile.h" | ||
| 12 | #import "BP7Controller.h" | ||
| 13 | #import "BP7.h" | ||
| 14 | #import "iHealthDeviceManagerModule.h" | ||
| 15 | |||
| 16 | @interface BP7Module() | ||
| 17 | @property (nonatomic, strong) NSNumber* previousPressure; | ||
| 18 | @property (nonatomic, assign) BOOL startSendWavelet; | ||
| 19 | @property (nonatomic, assign) BOOL isMeasuring; | ||
| 20 | |||
| 21 | @end | ||
| 22 | @implementation BP7Module | ||
| 23 | #define EVENT_NOTIFY @"BP7.MODULE.NOTIFY" | ||
| 24 | RCT_EXPORT_MODULE() | ||
| 25 | - (NSArray<NSString *> *)supportedEvents { | ||
| 26 | return @[@"event_notify", @"event_scan_device", @"event_scan_finish", | ||
| 27 | @"event_device_connected", @"event_device_connect_failed", | ||
| 28 | @"event_device_disconnect", @"event_authenticate_result", | ||
| 29 | @"event_notify_ts28b", @"event_notify_bg1", | ||
| 30 | @"action_connect_result_for_bg1"]; | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 | - (NSDictionary *)constantsToExport | ||
| 36 | { | ||
| 37 | return @{ | ||
| 38 | @"Event_Notify":EVENT_NOTIFY, | ||
| 39 | |||
| 40 | }; | ||
| 41 | } | ||
| 42 | + (BOOL)requiresMainQueueSetup | ||
| 43 | { | ||
| 44 | return YES; | ||
| 45 | } | ||
| 46 | |||
| 47 | #pragma mark | ||
| 48 | #pragma mark - Init | ||
| 49 | |||
| 50 | -(BP7*)getBP7WithMac:(NSString*)mac{ | ||
| 51 | |||
| 52 | BP7Controller *controller = [BP7Controller shareBP7Controller]; | ||
| 53 | NSArray *bpDeviceArray = [controller getAllCurrentBP7Instace]; | ||
| 54 | |||
| 55 | for(BP7 *tempDevice in bpDeviceArray){ | ||
| 56 | if([mac isEqualToString:tempDevice.serialNumber]){ | ||
| 57 | |||
| 58 | return tempDevice; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | return nil; | ||
| 63 | |||
| 64 | |||
| 65 | } | ||
| 66 | |||
| 67 | #pragma mark | ||
| 68 | #pragma mark - Notification | ||
| 69 | #pragma mark - BP7 | ||
| 70 | |||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | |||
| 75 | #pragma mark | ||
| 76 | #pragma mark - Method | ||
| 77 | |||
| 78 | |||
| 79 | #pragma mark-获取连接设备 | ||
| 80 | RCT_EXPORT_METHOD(getAllConnectedDevices){ | ||
| 81 | |||
| 82 | |||
| 83 | NSArray*bp7array= [[BP7Controller shareBP7Controller] getAllCurrentBP7Instace]; | ||
| 84 | |||
| 85 | NSMutableArray*deviceMacArray=[NSMutableArray array]; | ||
| 86 | |||
| 87 | for (int i=0; i<[bp7array count]; i++) { | ||
| 88 | |||
| 89 | BP7*bp7=[bp7array objectAtIndex:i]; | ||
| 90 | |||
| 91 | [deviceMacArray addObject:bp7.serialNumber]; | ||
| 92 | |||
| 93 | } | ||
| 94 | |||
| 95 | NSDictionary* deviceInfo = @{@"action":@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray}; | ||
| 96 | |||
| 97 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 98 | |||
| 99 | |||
| 100 | } | ||
| 101 | |||
| 102 | |||
| 103 | RCT_EXPORT_METHOD(conformAngle:(nonnull NSString *)mac){ | ||
| 104 | |||
| 105 | |||
| 106 | if ([self getBP7WithMac:mac]!=nil) { | ||
| 107 | __weak typeof(self) weakSelf = self; | ||
| 108 | |||
| 109 | |||
| 110 | [[self getBP7WithMac:mac] commandStartGetAngle:^(NSDictionary *angleDict) { | ||
| 111 | |||
| 112 | |||
| 113 | NSDictionary* response = @{ | ||
| 114 | kACTION:kACTION_ANGLE_BP, | ||
| 115 | |||
| 116 | kANGLE_BP:angleDict[@"angle"], | ||
| 117 | |||
| 118 | kWHICH_ARM:angleDict[@"isLeftHand"] | ||
| 119 | }; | ||
| 120 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 121 | |||
| 122 | } errorBlock:^(BPDeviceError error) { | ||
| 123 | |||
| 124 | |||
| 125 | NSLog(@"error %lu",(unsigned long)error); | ||
| 126 | |||
| 127 | weakSelf.isMeasuring = NO; | ||
| 128 | |||
| 129 | [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 130 | |||
| 131 | }]; | ||
| 132 | |||
| 133 | |||
| 134 | |||
| 135 | }else{ | ||
| 136 | |||
| 137 | NSLog(@"error %lu",(unsigned long)BPDidDisconnect); | ||
| 138 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 139 | self.isMeasuring = NO; | ||
| 140 | } | ||
| 141 | |||
| 142 | |||
| 143 | |||
| 144 | |||
| 145 | } | ||
| 146 | |||
| 147 | |||
| 148 | |||
| 149 | |||
| 150 | |||
| 151 | RCT_EXPORT_METHOD(startMeasure:(nonnull NSString *)mac){ | ||
| 152 | |||
| 153 | _previousPressure = @(0); | ||
| 154 | self.startSendWavelet = NO; | ||
| 155 | if ([self getBP7WithMac:mac]!=nil) { | ||
| 156 | __weak typeof(self) weakSelf = self; | ||
| 157 | [[self getBP7WithMac:mac] commandStartMeasureWithZeroingState:^(BOOL isComplete) { | ||
| 158 | weakSelf.isMeasuring = YES; | ||
| 159 | NSDictionary* response = @{ | ||
| 160 | kACTION:isComplete ? kACTION_ZOREING_BP : kACTION_ZOREOVER_BP, | ||
| 161 | }; | ||
| 162 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 163 | } pressure:^(NSArray *pressureArr) { | ||
| 164 | NSLog(@"pressure %@",pressureArr); | ||
| 165 | weakSelf.isMeasuring = YES; | ||
| 166 | [weakSelf sendPresssre:pressureArr.firstObject wavelet:nil isHeartPulse:NO]; | ||
| 167 | } waveletWithHeartbeat:^(NSArray *waveletArr) { | ||
| 168 | NSLog(@"xiaoboWithHeart %@",waveletArr); | ||
| 169 | weakSelf.isMeasuring = YES; | ||
| 170 | [weakSelf sendPresssre:nil wavelet:waveletArr isHeartPulse:YES]; | ||
| 171 | } waveletWithoutHeartbeat:^(NSArray *waveletArr) { | ||
| 172 | weakSelf.isMeasuring = YES; | ||
| 173 | NSLog(@"xiaoboNoHeart %@",waveletArr); | ||
| 174 | [weakSelf sendPresssre:nil wavelet:waveletArr isHeartPulse:NO]; | ||
| 175 | } result:^(NSDictionary *resultDict) { | ||
| 176 | NSLog(@"result %@",resultDict); | ||
| 177 | weakSelf.startSendWavelet = NO; | ||
| 178 | weakSelf.isMeasuring = NO; | ||
| 179 | NSDictionary* response = @{ | ||
| 180 | kACTION:kACTION_ONLINE_RESULT_BP, | ||
| 181 | kHIGH_BLOOD_PRESSURE_BP:resultDict[@"sys"], | ||
| 182 | kLOW_BLOOD_PRESSURE_BP:resultDict[@"dia"], | ||
| 183 | kPULSE_BP:resultDict[@"heartRate"], | ||
| 184 | kMEASUREMENT_AHR_BP:resultDict[@"irregular"], | ||
| 185 | kDATAID:resultDict[@"dataID"], | ||
| 186 | }; | ||
| 187 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 188 | } errorBlock:^(BPDeviceError error) { | ||
| 189 | NSLog(@"error %lu",(unsigned long)error); | ||
| 190 | weakSelf.startSendWavelet = NO; | ||
| 191 | weakSelf.isMeasuring = NO; | ||
| 192 | [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 193 | |||
| 194 | }]; | ||
| 195 | |||
| 196 | |||
| 197 | }else{ | ||
| 198 | |||
| 199 | NSLog(@"error %d",BPDidDisconnect); | ||
| 200 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 201 | self.isMeasuring = NO; | ||
| 202 | } | ||
| 203 | |||
| 204 | |||
| 205 | } | ||
| 206 | |||
| 207 | - (void)sendPresssre:(NSNumber*)pressure wavelet:(NSArray*)waveletArray isHeartPulse:(BOOL)heartPulse{ | ||
| 208 | |||
| 209 | if (pressure) { | ||
| 210 | self.previousPressure = pressure; | ||
| 211 | } | ||
| 212 | if (waveletArray.count > 0) { | ||
| 213 | self.startSendWavelet = YES; | ||
| 214 | } | ||
| 215 | if (pressure && !self.startSendWavelet) { | ||
| 216 | NSDictionary* response = @{ | ||
| 217 | kACTION:kACTION_ONLINE_PRESSURE_BP, | ||
| 218 | kBLOOD_PRESSURE_BP:pressure, | ||
| 219 | }; | ||
| 220 | [BPProfileModule sendEventToEmitter:self eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 221 | }else if (waveletArray.count > 0 && self.startSendWavelet){ | ||
| 222 | NSDictionary* response = @{ | ||
| 223 | kACTION:kACTION_ONLINE_PULSEWAVE_BP, | ||
| 224 | kBLOOD_PRESSURE_BP:self.previousPressure, | ||
| 225 | kFLAG_HEARTBEAT_BP:@(heartPulse), | ||
| 226 | kPULSEWAVE_BP:waveletArray | ||
| 227 | }; | ||
| 228 | [BPProfileModule sendEventToEmitter:self eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | |||
| 233 | RCT_EXPORT_METHOD(stopMeasure:(nonnull NSString *)mac){ | ||
| 234 | |||
| 235 | if (!self.isMeasuring) { | ||
| 236 | NSLog(@"error %d",401); | ||
| 237 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:401]; | ||
| 238 | return; | ||
| 239 | } | ||
| 240 | if ([self getBP7WithMac:mac]!=nil) { | ||
| 241 | __weak typeof(self) weakSelf = self; | ||
| 242 | |||
| 243 | [[self getBP7WithMac:mac] stopBPMeassureSuccessBlock:^{ | ||
| 244 | |||
| 245 | } errorBlock:^(BPDeviceError error) { | ||
| 246 | |||
| 247 | NSLog(@"error %lu",(unsigned long)error); | ||
| 248 | [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 249 | |||
| 250 | }]; | ||
| 251 | |||
| 252 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | ||
| 253 | NSDictionary* response = @{ | ||
| 254 | kACTION:kACTION_INTERRUPTED_BP, | ||
| 255 | }; | ||
| 256 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 257 | weakSelf.isMeasuring = NO; | ||
| 258 | }); | ||
| 259 | }else{ | ||
| 260 | |||
| 261 | NSLog(@"error %lu",(unsigned long)BPDidDisconnect); | ||
| 262 | self.isMeasuring = NO; | ||
| 263 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 264 | |||
| 265 | } | ||
| 266 | |||
| 267 | } | ||
| 268 | |||
| 269 | RCT_EXPORT_METHOD(getBattery:(nonnull NSString *)mac){ | ||
| 270 | |||
| 271 | |||
| 272 | if ([self getBP7WithMac:mac]!=nil) { | ||
| 273 | __weak typeof(self) weakSelf = self; | ||
| 274 | [[self getBP7WithMac:mac] commandEnergy:^(NSNumber *energyValue) { | ||
| 275 | NSDictionary* response = @{ | ||
| 276 | kACTION:kACTION_BATTERY_BP, | ||
| 277 | kBATTERY_BP:energyValue | ||
| 278 | }; | ||
| 279 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 280 | } errorBlock:^(BPDeviceError error) { | ||
| 281 | NSLog(@"error %lu",(unsigned long)error); | ||
| 282 | [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 283 | }]; | ||
| 284 | |||
| 285 | }else{ | ||
| 286 | |||
| 287 | NSLog(@"error %lu",(unsigned long)BPDidDisconnect); | ||
| 288 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 289 | |||
| 290 | } | ||
| 291 | |||
| 292 | |||
| 293 | |||
| 294 | |||
| 295 | } | ||
| 296 | |||
| 297 | |||
| 298 | RCT_EXPORT_METHOD(enbleOffline:(nonnull NSString *)mac){ | ||
| 299 | |||
| 300 | |||
| 301 | if ([self getBP7WithMac:mac]!=nil) { | ||
| 302 | __block BOOL success = YES; | ||
| 303 | __weak typeof(self) weakSelf = self; | ||
| 304 | [[self getBP7WithMac:mac] commandSetOffline:YES errorBlock:^(BPDeviceError error) { | ||
| 305 | success = NO; | ||
| 306 | [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 307 | }]; | ||
| 308 | |||
| 309 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | ||
| 310 | if (success) { | ||
| 311 | NSDictionary* response = @{ | ||
| 312 | kACTION:kACTION_ENABLE_OFFLINE_BP, | ||
| 313 | }; | ||
| 314 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 315 | } | ||
| 316 | }); | ||
| 317 | |||
| 318 | }else{ | ||
| 319 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 320 | } | ||
| 321 | |||
| 322 | } | ||
| 323 | |||
| 324 | |||
| 325 | RCT_EXPORT_METHOD(disableOffline:(nonnull NSString *)mac){ | ||
| 326 | |||
| 327 | |||
| 328 | if ([self getBP7WithMac:mac]!=nil) { | ||
| 329 | __block BOOL success = YES; | ||
| 330 | __weak typeof(self) weakSelf = self; | ||
| 331 | [[self getBP7WithMac:mac] commandSetOffline:NO errorBlock:^(BPDeviceError error) { | ||
| 332 | success = NO; | ||
| 333 | [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 334 | }]; | ||
| 335 | |||
| 336 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | ||
| 337 | if (success) { | ||
| 338 | NSDictionary* response = @{ | ||
| 339 | kACTION:kACTION_DISENABLE_OFFLINE_BP, | ||
| 340 | }; | ||
| 341 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 342 | } | ||
| 343 | }); | ||
| 344 | |||
| 345 | }else{ | ||
| 346 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 347 | } | ||
| 348 | |||
| 349 | |||
| 350 | } | ||
| 351 | |||
| 352 | |||
| 353 | RCT_EXPORT_METHOD(isEnableOffline:(nonnull NSString *)mac){ | ||
| 354 | |||
| 355 | |||
| 356 | if ([self getBP7WithMac:mac]!=nil) { | ||
| 357 | __weak typeof(self) weakSelf = self; | ||
| 358 | [[self getBP7WithMac:mac] commandFunction:^(NSDictionary *dic) { | ||
| 359 | NSDictionary* response = @{ | ||
| 360 | kACTION:kACTION_IS_ENABLE_OFFLINE, | ||
| 361 | kIS_ENABLE_OFFLINE:dic[@"offlineOpen"] | ||
| 362 | }; | ||
| 363 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 364 | } errorBlock:^(BPDeviceError error) { | ||
| 365 | [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 366 | }]; | ||
| 367 | }else{ | ||
| 368 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 369 | } | ||
| 370 | |||
| 371 | } | ||
| 372 | |||
| 373 | |||
| 374 | |||
| 375 | RCT_EXPORT_METHOD(getOfflineNum:(nonnull NSString *)mac){ | ||
| 376 | |||
| 377 | |||
| 378 | |||
| 379 | if ([self getBP7WithMac:mac]!=nil) { | ||
| 380 | |||
| 381 | __weak typeof(self) weakSelf = self; | ||
| 382 | |||
| 383 | [[self getBP7WithMac:mac] commandTransferMemoryTotalCount:^(NSNumber *count) { | ||
| 384 | |||
| 385 | NSDictionary* response = @{ | ||
| 386 | kACTION:kACTION_HISTORICAL_NUM_BP, | ||
| 387 | kHISTORICAL_NUM_BP:count | ||
| 388 | }; | ||
| 389 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 390 | |||
| 391 | } errorBlock:^(BPDeviceError error) { | ||
| 392 | |||
| 393 | }]; | ||
| 394 | }else{ | ||
| 395 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 396 | } | ||
| 397 | |||
| 398 | |||
| 399 | |||
| 400 | // if ([self getBP7WithMac:mac]!=nil) { | ||
| 401 | // __weak typeof(self) weakSelf = self; | ||
| 402 | // | ||
| 403 | // [[self getBP7WithMac:mac] commandBatchUpload:^(NSNumber *count) { | ||
| 404 | // NSDictionary* response = @{ | ||
| 405 | // kACTION:kACTION_HISTORICAL_NUM_BP, | ||
| 406 | // kHISTORICAL_NUM_BP:count | ||
| 407 | // }; | ||
| 408 | // [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 409 | // | ||
| 410 | // } progress:^(NSNumber *progressValue) { | ||
| 411 | // | ||
| 412 | // } dataArray:^(NSArray *bachArray) { | ||
| 413 | // NSMutableArray * historyDataArray = [NSMutableArray array]; | ||
| 414 | // | ||
| 415 | // for(NSDictionary *dataDict in bachArray) | ||
| 416 | // { | ||
| 417 | // | ||
| 418 | // NSDate *date = [dataDict objectForKey:@"time"]; | ||
| 419 | // | ||
| 420 | // //将时间格式转化成字符串,适配plugin和react native | ||
| 421 | // NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init]; | ||
| 422 | // [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | ||
| 423 | // NSString *dateStr = [mydateFormatter stringFromDate:date]; | ||
| 424 | // NSDictionary* historyDataDict = @{ | ||
| 425 | // kMEASUREMENT_DATE_BP:dateStr, | ||
| 426 | // kHIGH_BLOOD_PRESSURE_BP:dataDict[@"sys"], | ||
| 427 | // kLOW_BLOOD_PRESSURE_BP:dataDict[@"dia"], | ||
| 428 | // kPULSE_BP:dataDict[@"heartRate"], | ||
| 429 | // kMEASUREMENT_AHR_BP:dataDict[@"irregular"], | ||
| 430 | // // kMEASUREMENT_HSD_BP:dataDict[@"hsdValue"], | ||
| 431 | // kDATAID:dataDict[@"dataID"] | ||
| 432 | // }; | ||
| 433 | // [historyDataArray addObject:historyDataDict]; | ||
| 434 | // | ||
| 435 | // | ||
| 436 | // } | ||
| 437 | // | ||
| 438 | // if (historyDataArray.count > 0) { | ||
| 439 | // NSDictionary* deviceInfo = @{kACTION:kACTION_HISTORICAL_DATA_BP,kHISTORICAL_DATA_BP:[historyDataArray copy] }; | ||
| 440 | // [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:deviceInfo]; | ||
| 441 | // } | ||
| 442 | // | ||
| 443 | // } errorBlock:^(BPDeviceError error) { | ||
| 444 | // [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 445 | // | ||
| 446 | // }]; | ||
| 447 | // | ||
| 448 | // }else{ | ||
| 449 | // [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 450 | // } | ||
| 451 | } | ||
| 452 | |||
| 453 | |||
| 454 | |||
| 455 | RCT_EXPORT_METHOD(getOfflineData:(nonnull NSString *)mac){ | ||
| 456 | |||
| 457 | |||
| 458 | if ([self getBP7WithMac:mac]!=nil) { | ||
| 459 | __weak typeof(self) weakSelf = self; | ||
| 460 | [[self getBP7WithMac:mac] commandBatchUpload:^(NSNumber *count) { | ||
| 461 | NSDictionary* response = @{ | ||
| 462 | kACTION:kACTION_HISTORICAL_NUM_BP, | ||
| 463 | kHISTORICAL_NUM_BP:count | ||
| 464 | }; | ||
| 465 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 466 | |||
| 467 | } progress:^(NSNumber *progressValue) { | ||
| 468 | |||
| 469 | } dataArray:^(NSArray *bachArray) { | ||
| 470 | NSMutableArray * historyDataArray = [NSMutableArray array]; | ||
| 471 | |||
| 472 | for(NSDictionary *dataDict in bachArray) | ||
| 473 | { | ||
| 474 | |||
| 475 | NSDate *date = [dataDict objectForKey:@"time"]; | ||
| 476 | |||
| 477 | //将时间格式转化成字符串,适配plugin和react native | ||
| 478 | NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init]; | ||
| 479 | [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | ||
| 480 | NSString *dateStr = [mydateFormatter stringFromDate:date]; | ||
| 481 | NSDictionary* historyDataDict = @{ | ||
| 482 | kMEASUREMENT_DATE_BP:dateStr, | ||
| 483 | kHIGH_BLOOD_PRESSURE_BP:dataDict[@"sys"], | ||
| 484 | kLOW_BLOOD_PRESSURE_BP:dataDict[@"dia"], | ||
| 485 | kPULSE_BP:dataDict[@"heartRate"], | ||
| 486 | kMEASUREMENT_AHR_BP:dataDict[@"irregular"], | ||
| 487 | // kMEASUREMENT_HSD_BP:dataDict[@"hsdValue"], | ||
| 488 | kDATAID:dataDict[@"dataID"] | ||
| 489 | }; | ||
| 490 | [historyDataArray addObject:historyDataDict]; | ||
| 491 | |||
| 492 | |||
| 493 | } | ||
| 494 | |||
| 495 | if (historyDataArray.count > 0) { | ||
| 496 | NSDictionary* deviceInfo = @{kACTION:kACTION_HISTORICAL_DATA_BP,kHISTORICAL_DATA_BP:[historyDataArray copy] }; | ||
| 497 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:deviceInfo]; | ||
| 498 | } | ||
| 499 | |||
| 500 | } errorBlock:^(BPDeviceError error) { | ||
| 501 | [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 502 | |||
| 503 | }]; | ||
| 504 | |||
| 505 | }else{ | ||
| 506 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 507 | } | ||
| 508 | |||
| 509 | } | ||
| 510 | |||
| 511 | |||
| 512 | |||
| 513 | RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){ | ||
| 514 | NSLog(@"iOS doesn't support disconnect normal BT devices"); | ||
| 515 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:900]; | ||
| 516 | |||
| 517 | } | ||
| 518 | |||
| 519 | |||
| 520 | |||
| 521 | @end | ||
