summaryrefslogtreecommitdiff
path: root/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS4SModule.m
diff options
context:
space:
mode:
authorhc <haocheng.xie@respiree.com>2026-04-13 15:17:52 +0800
committerhc <haocheng.xie@respiree.com>2026-04-13 15:17:52 +0800
commitd6d9a09d505d11148599a95a5be3e1351edbe0ac (patch)
treea5f5891983d1ff207e99f683a5e151519cef4980 /libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS4SModule.m
parente4fb9966e762852bf17f21c8406501d42fae0b61 (diff)
Local iHealth SDK, device detail screen, iOS event fixes
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS4SModule.m')
-rw-r--r--libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS4SModule.m257
1 files changed, 257 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS4SModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS4SModule.m
new file mode 100644
index 0000000..8538c6f
--- /dev/null
+++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS4SModule.m
@@ -0,0 +1,257 @@
1//
2// HS4SModule.m
3// ReactNativeIOSLibrary
4//
5// Created by ihealth on 16/12/2.
6// Copyright © 2016年 daiqingquan. All rights reserved.
7//
8
9#import "HS4SModule.h"
10#import "HSProfileModule.h"
11#import "HSMacroFile.h"
12#import "HS4Controller.h"
13#import "HS4.h"
14#import "iHealthDeviceManagerModule.h"
15#import "ManageDeviceController.h"
16
17
18#define EVENT_NOTIFY @"HS4.MODULE.NOTIFY"
19
20@implementation HS4SModule
21
22
23RCT_EXPORT_MODULE()
24- (NSArray<NSString *> *)supportedEvents {
25 return @[@"event_notify", @"event_scan_device", @"event_scan_finish",
26 @"event_device_connected", @"event_device_connect_failed",
27 @"event_device_disconnect", @"event_authenticate_result",
28 @"event_notify_ts28b", @"event_notify_bg1",
29 @"action_connect_result_for_bg1"];
30}
31
32
33#pragma mark-init
34
35-(NSDictionary *)constantsToExport{
36 return @{
37 @"Event_Notify" : EVENT_NOTIFY
38 };
39}
40
41+ (BOOL)requiresMainQueueSetup
42{
43 return YES;
44}
45-(HS4 *)getHS4WithMac:(NSString *)mac{
46 HS4Controller *controller = [HS4Controller shareIHHs4Controller];
47 NSArray *hs4DeviceArray = [controller getAllCurrentHS4Instace];
48 for (HS4 *tempHS4 in hs4DeviceArray) {
49 if ([mac isEqualToString:tempHS4.deviceID]){
50 return tempHS4;
51 break;
52 }
53 }
54 return nil;
55}
56
57#pragma mark
58#pragma mark - Notification
59#pragma mark - HS4
60-(void)DeviceConnectForHS4S:(NSNotification *)notify{
61 HS4Controller *controller = [HS4Controller shareIHHs4Controller];
62 NSArray *hs4DeviceArray = [controller getAllCurrentHS4Instace];
63
64 HS4 *hs4Instance = [hs4DeviceArray objectAtIndex:0];
65}
66
67#pragma mark
68#pragma mark - Method
69
70
71#pragma mark-获取连接设备
72RCT_EXPORT_METHOD(getAllConnectedDevices){
73
74
75 NSArray*hs4array= [[HS4Controller shareIHHs4Controller] getAllCurrentHS4Instace];
76
77 NSMutableArray*deviceMacArray=[NSMutableArray array];
78
79 for (int i=0; i<[hs4array count]; i++) {
80
81 HS4*hs4=[hs4array objectAtIndex:i];
82
83 [deviceMacArray addObject:hs4.deviceID];
84
85 }
86
87 NSDictionary* deviceInfo = @{@"action":@"action_get_all_connected_devices",@"devices":deviceMacArray};
88 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
89
90
91}
92
93
94RCT_EXPORT_METHOD(getOfflineData:(nonnull NSString*)mac){
95 if ([self getHS4WithMac:mac] != nil) {
96
97 NSLog(@"上传离线数据");
98 [[self getHS4WithMac:mac]commandTransferMemorryData:^(NSDictionary *startDataDictionary) {
99
100
101 } DisposeProgress:^(NSNumber *progress) {
102
103 } MemorryData:^(NSArray *historyDataArray) {
104
105 if(historyDataArray != nil){
106
107 if(historyDataArray.count){
108
109 NSMutableArray*dataArray=[NSMutableArray array];
110
111 for (int i=0; i<historyDataArray.count; i++) {
112
113 NSDate *tempDate = [[historyDataArray objectAtIndex:i] objectForKey:@"date"];
114
115
116 NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init];
117 [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
118 NSString *dateStr = [mydateFormatter stringFromDate:tempDate];
119
120
121 NSDictionary*dic=@{DATAID:[[historyDataArray objectAtIndex:i] objectForKey:@"dataID"],MEASUREMENT_DATE_HS:dateStr,WEIGHT_HS:[[historyDataArray objectAtIndex:i] objectForKey:@"weight"]};
122
123 [dataArray addObject:dic];
124 }
125
126
127 NSDictionary *deviceInfo = @{@"mac":mac,@"action":ACTION_HISTORICAL_DATA_HS,HISTORDATA_HS:dataArray};
128
129 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
130 NSLog(@"historyDataArray:%@",historyDataArray);
131
132 }
133
134 }
135 } FinishTransmission:^{
136 NSDictionary *deviceInfo = @{@"mac":mac,@"action":ACTION_HISTORICAL_DATA_COMPLETE_HS};
137
138 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
139 } DisposeErrorBlock:^(HS4DeviceError errorID) {
140 NSString *errorMassage = [NSString string];
141 NSLog(@"errorID:%d",errorID);
142 switch (errorID) {
143 case 1:
144 errorMassage = @"Battery level is low";
145 break;
146 case 2:
147 errorMassage = @"The Scale failed to initialize.";
148 break;
149 case 5:
150 errorMassage = @"Bluetooth connection error.";
151 break;
152 case 7:
153 errorMassage = @"Invalidate.";
154 break;
155 case 8:
156 errorMassage = @"Scale memory access error.";
157 break;
158 case 9:
159 errorMassage = @"No History Data.";
160 break;
161 case 10:
162 errorMassage = @"Device disconnect.";
163 break;
164// case 11:
165// errorMassage = @"Communication error.";
166// break;
167 default:
168 break;
169 }
170 if(errorID == 9){
171 NSDictionary *deviceInfo = @{@"mac":mac,@"action":ACTION_NO_HISTORICALDATA,ERROR_DESCRIPTION_HS:@"No History Data."};
172
173 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
174 }
175 else if(errorID != 11){
176 NSDictionary *deviceInfo = @{@"mac":mac,@"action":ACTION_ERROR_HS,ERROR_NUM_HS:errorMassage};
177
178 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];}
179 }];
180 }
181}
182
183
184RCT_EXPORT_METHOD(measureOnline:(nonnull NSString*)mac :(nonnull NSNumber*)unit :(nonnull NSNumber*)userId){
185 if ([self getHS4WithMac:mac] != nil) {
186
187 [[self getHS4WithMac:mac]commandMeasureWithUint:unit.intValue Weight:^(NSNumber *unStableWeight) {
188 NSDictionary *deviceInfo = @{@"mac":mac,@"action":ACTION_LIVEDATA_HS,LIVEDATA_HS:unStableWeight};
189 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
190
191 } StableWeight:^(NSDictionary *StableWeightDic) {
192 NSDictionary *deviceInfo =@{@"mac":mac,@"action":ACTION_ONLINE_RESULT_HS,DATAID:[StableWeightDic valueForKey:@"dataID"],WEIGHT_HS:[StableWeightDic valueForKey:@"Weight"] };
193
194 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
195 } DisposeErrorBlock:^(HS4DeviceError errorID) {
196 NSString *errorMassage = [NSString string];
197 switch (errorID) {
198 case 1:
199 errorMassage = @"Battery level is low.";
200 break;
201 case 2:
202 errorMassage = @"The Scale failed to initialize.";
203 break;
204 case 3:
205 errorMassage = @"Maximum weight has been exceeded.";
206 break;
207 case 4:
208 errorMassage = @"The Scale can't capture a steady reading.";
209 break;
210 case 5:
211 errorMassage = @"Bluetooth connection error.";
212 break;
213 case 6:
214 errorMassage = @"Movement while measuring.";
215 break;
216 case 7:
217 errorMassage = @"Invalidate.";
218 break;
219 case 10:
220 errorMassage = @"Device disconnect.";
221 break;
222 case 11:
223 errorMassage = @"Communication error.";
224 break;
225 case 12:
226 errorMassage = @"HS4DeviceRecWeightError.";
227 break;
228 default:
229 break;
230 }
231
232 NSDictionary *deviceInfo = @{@"mac":mac,@"action":ACTION_ERROR_HS,ERROR_NUM_HS:errorMassage};
233 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
234 }];
235 }
236
237}
238
239RCT_EXPORT_METHOD(disconnect:(nonnull NSString*)mac){
240 if ([self getHS4WithMac:mac] != nil){
241
242 [[self getHS4WithMac:mac]commandDisconnectDevice];
243 NSLog(@"End device connnect!");
244
245 }else{
246
247 }
248}
249- (void)sendErrorWithCode:(NSInteger)errorCode{
250 [self sendEventWithAction:@"ACTION_ERROR_HS" keyString:@"value" valueString:@(errorCode)];
251}
252
253- (void)sendEventWithAction:(NSString*)actionName keyString:(NSString*)key valueString:(id)value{
254 [self sendEventWithName:@"HS4.MODULE.NOTIFY" body:@{@"action":actionName,key:value}];
255}
256
257@end