diff options
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/TS28BModule.m')
| -rw-r--r-- | libs/ihealth-sdk/ios/ReactNativeIOSLibrary/TS28BModule.m | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/TS28BModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/TS28BModule.m new file mode 100644 index 0000000..5e51e7c --- /dev/null +++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/TS28BModule.m | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | // | ||
| 2 | // TS28BModule.m | ||
| 3 | // ReactNativeIOSLibrary | ||
| 4 | // | ||
| 5 | // Created by user on 2019/11/12. | ||
| 6 | // Copyright © 2019 daiqingquan. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "TS28BModule.h" | ||
| 10 | #import "TS28BHeader.h" | ||
| 11 | |||
| 12 | #define EVENT_NOTIFY @"event_notify_ts28b" | ||
| 13 | #define kMAC_KEY @"mac" | ||
| 14 | #define kACTION_KEY @"action" | ||
| 15 | |||
| 16 | @interface TS28BModule()<TS28BControllerDelegate> | ||
| 17 | |||
| 18 | @property (strong, nonatomic) TS28BController *ts28bController; | ||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | @end | ||
| 23 | |||
| 24 | @implementation TS28BModule | ||
| 25 | |||
| 26 | |||
| 27 | RCT_EXPORT_MODULE() | ||
| 28 | - (NSArray<NSString *> *)supportedEvents { | ||
| 29 | return @[@"event_notify", @"event_scan_device", @"event_scan_finish", | ||
| 30 | @"event_device_connected", @"event_device_connect_failed", | ||
| 31 | @"event_device_disconnect", @"event_authenticate_result", | ||
| 32 | @"event_notify_ts28b", @"event_notify_bg1", | ||
| 33 | @"action_connect_result_for_bg1"]; | ||
| 34 | } | ||
| 35 | |||
| 36 | |||
| 37 | - (NSDictionary *)constantsToExport | ||
| 38 | { | ||
| 39 | return @{ @"Event_Notify": EVENT_NOTIFY }; | ||
| 40 | } | ||
| 41 | |||
| 42 | + (BOOL)requiresMainQueueSetup | ||
| 43 | { | ||
| 44 | return YES; | ||
| 45 | } | ||
| 46 | |||
| 47 | |||
| 48 | RCT_EXPORT_METHOD(getAllConnectedDevices){ | ||
| 49 | |||
| 50 | [[NSNotificationCenter defaultCenter] postNotificationName:@"getAllTS28BConnectedDevices" object:self]; | ||
| 51 | } | ||
| 52 | |||
| 53 | RCT_EXPORT_METHOD(measure:(nonnull NSString *)mac){ | ||
| 54 | |||
| 55 | |||
| 56 | self.ts28bController = [TS28BController sharedController]; | ||
| 57 | |||
| 58 | self.ts28bController.delegate = self; | ||
| 59 | |||
| 60 | // if ([self getDeviceWithMac:mac] != nil) { | ||
| 61 | // | ||
| 62 | // [[self getDeviceWithMac:mac] commandStartMeasure:^(NSDictionary *result) { | ||
| 63 | // | ||
| 64 | // NSDictionary* deviceInfo = @{kACTION_KEY:@"ACTION_GET_MEASURE",@"bodyFlag":[result objectForKey:@"bodyFlag"],@"unit":[result objectForKey:@"unit"],@"result":[result objectForKey:@"result"]}; | ||
| 65 | // | ||
| 66 | // [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 67 | // | ||
| 68 | // | ||
| 69 | // | ||
| 70 | // }]; | ||
| 71 | // | ||
| 72 | // } | ||
| 73 | |||
| 74 | } | ||
| 75 | |||
| 76 | //断开连接 | ||
| 77 | RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){ | ||
| 78 | |||
| 79 | [[NSNotificationCenter defaultCenter] postNotificationName:@"disconnectTS28B" object:self]; | ||
| 80 | } | ||
| 81 | |||
| 82 | #pragma mark - TS28B delegate | ||
| 83 | |||
| 84 | - (void)controller:(TS28BController *)controller didDiscoverDevice:(TS28B *)device{ | ||
| 85 | NSLog(@"搜索到设备的代理"); | ||
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | } | ||
| 90 | - (void)controller:(TS28BController *)controller didConnectSuccessDevice:(TS28B *)device{ | ||
| 91 | NSLog(@"连接成功的代理"); | ||
| 92 | // self.connectedDevice = device; | ||
| 93 | // NSLog(@"%@",[NSString stringWithFormat:@"连接成功:%@ \nSerial Number:%@\nModel Number%@\nFirmware:%@\nHardware:%@\nSoftware:%@\nManufacture:%@\nSystemID:%@",device.peripheral.name,device.serialNumber,device.modelNumber,device.firmwareVersion,device.hardwareVersion,device.softwareVersion,device.manufacturerName,device.systemID]); | ||
| 94 | |||
| 95 | |||
| 96 | } | ||
| 97 | - (void)controller:(TS28BController *)controller didConnectFailDevice:(TS28B *)device{ | ||
| 98 | NSLog(@"连接失败的代理"); | ||
| 99 | // self.recordTextView.text = @"连接失败"; | ||
| 100 | |||
| 101 | } | ||
| 102 | - (void)controller:(TS28BController *)controller didDisconnectDevice:(TS28B *)device{ | ||
| 103 | NSLog(@"断开连接的代理"); | ||
| 104 | // self.recordTextView.text = @"连接断开"; | ||
| 105 | } | ||
| 106 | - (void)controller:(TS28BController *)controller device:(TS28B *)device didUpdateTemperature:(float)value temperatureUnit:(TemperatureUnit)unit measureDate:(NSDate *)date measureLocation:(TemperatureType)type{ | ||
| 107 | |||
| 108 | // self.valueLabel.text = [NSString stringWithFormat:@"%.1f %@",value,(unit == TemperatureUnit_C)?@"C":@"F"]; | ||
| 109 | |||
| 110 | NSDictionary* deviceInfo = @{kACTION_KEY:@"ACTION_GET_MEASURE",@"bodyFlag":[NSNumber numberWithInt:type],@"unit":[NSNumber numberWithInt:unit],@"result":[NSNumber numberWithFloat:value]}; | ||
| 111 | |||
| 112 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 113 | } | ||
| 114 | |||
| 115 | |||
| 116 | @end | ||
