summaryrefslogtreecommitdiff
path: root/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/NT13BModule.m
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/NT13BModule.m')
-rw-r--r--libs/ihealth-sdk/ios/ReactNativeIOSLibrary/NT13BModule.m103
1 files changed, 103 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/NT13BModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/NT13BModule.m
new file mode 100644
index 0000000..158de43
--- /dev/null
+++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/NT13BModule.m
@@ -0,0 +1,103 @@
1//
2// NT13BModule.m
3// ReactNativeIOSLibrary
4//
5// Created by user on 2019/11/12.
6// Copyright © 2019 daiqingquan. All rights reserved.
7//
8
9#import "NT13BModule.h"
10#import "NT13BHeader.h"
11#import "NT13BProfileModule.h"
12
13@implementation NT13BModule
14RCT_EXPORT_MODULE()
15- (NSArray<NSString *> *)supportedEvents {
16 return @[@"event_notify", @"event_scan_device", @"event_scan_finish",
17 @"event_device_connected", @"event_device_connect_failed",
18 @"event_device_disconnect", @"event_authenticate_result",
19 @"event_notify_ts28b", @"event_notify_bg1",
20 @"action_connect_result_for_bg1"];
21}
22
23
24- (NSDictionary *)constantsToExport
25{
26 return @{ @"Event_Notify": NT13B_EVENT_NOTIFY ,
27
28 };
29}
30
31+ (BOOL)requiresMainQueueSetup
32{
33 return YES;
34}
35
36
37-(NT13B*)getDeviceWithMac:(NSString*)mac{
38
39 NT13BController *controller = [NT13BController shareIHNT13BController];
40 NSArray *nt13bDeviceArray = [controller getAllCurrentNT13BInstace];
41
42 for(NT13B *tempDevice in nt13bDeviceArray){
43 if([mac isEqualToString:tempDevice.serialNumber]){
44
45 return tempDevice;
46 }
47 }
48 return nil;
49}
50
51RCT_EXPORT_METHOD(getAllConnectedDevices){
52
53
54 NSArray*nt13bDeviceArray= [[NT13BController shareIHNT13BController] getAllCurrentNT13BInstace];
55
56 NSMutableArray*deviceMacArray=[NSMutableArray array];
57
58 for (int i=0; i<[nt13bDeviceArray count]; i++) {
59
60 NT13B *nt13b = [nt13bDeviceArray objectAtIndex:i];
61
62 [deviceMacArray addObject:nt13b.serialNumber];
63
64 }
65
66 NSDictionary* deviceInfo = @{NT13B_ACTION:kACTION_GET_ALL_CONNECTED_DEVICES,NT13B_DEVICE:deviceMacArray};
67
68 [self sendEventWithName:NT13B_EVENT_NOTIFY body:deviceInfo];
69}
70
71RCT_EXPORT_METHOD(measure:(nonnull NSString *)mac){
72
73
74 if ([self getDeviceWithMac:mac] != nil) {
75
76 [[self getDeviceWithMac:mac] commandStartMeasure:^(NSDictionary *result) {
77
78 NSDictionary* deviceInfo = @{NT13B_ACTION:@"action_measurement_result",NT13B_THERMOMETER_TYPE:[result objectForKey:@"bodyFlag"],NT13B_UNIT_FLAG:[result objectForKey:@"unit"],NT13B_RESULT:[result objectForKey:@"result"]};
79
80 [self sendEventWithName:NT13B_EVENT_NOTIFY body:deviceInfo];
81
82
83
84 }];
85
86 }
87
88}
89
90//断开连接
91RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){
92 if ([self getDeviceWithMac:mac]!=nil) {
93
94 [[self getDeviceWithMac:mac] commandDisconnect:^(BOOL result) {
95
96
97 }];
98 }else{
99
100 }
101}
102
103@end