summaryrefslogtreecommitdiff
path: root/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS6Module.m
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS6Module.m')
-rw-r--r--libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS6Module.m339
1 files changed, 339 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS6Module.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS6Module.m
new file mode 100644
index 0000000..401697b
--- /dev/null
+++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS6Module.m
@@ -0,0 +1,339 @@
1//
2// HS6Module.m
3// ReactNativeIOSLibrary
4//
5// Created by ihealth on 16/12/12.
6// Copyright © 2016年 daiqingquan. All rights reserved.
7//
8
9#import "HS6Module.h"
10#import "HS6ProfileModule.h"
11#import "HSMacroFile.h"
12#import "iHealthHS6.h"
13#import "HealthUser.h"
14#import "iHealthDeviceManagerModule.h"
15
16#define EVENT_NOTIFY @"HS6.MODULE.NOTIFY"
17
18#define HS6_CLIENT_ID @"e33d489fdd6d4961a33c4065f7cedb30"
19
20#define HS6_CLIENT_SECRET @"17075697306e4930b87beffc58ceb2a4"
21
22@implementation HS6Module{
23
24 NSString*userAccount;
25
26}
27
28
29RCT_EXPORT_MODULE()
30- (NSArray<NSString *> *)supportedEvents {
31 return @[@"event_notify", @"event_scan_device", @"event_scan_finish",
32 @"event_device_connected", @"event_device_connect_failed",
33 @"event_device_disconnect", @"event_authenticate_result",
34 @"event_notify_ts28b", @"event_notify_bg1",
35 @"action_connect_result_for_bg1"];
36}
37
38
39#pragma mark-init
40
41-(NSDictionary *)constantsToExport{
42 return @{
43 @"Event_Notify" : EVENT_NOTIFY
44 };
45}
46+ (BOOL)requiresMainQueueSetup
47{
48 return YES;
49}
50- (void)sendErrorWithCode:(NSInteger)errorCode{
51 [self sendEventWithAction:@"ACTION_ERROR_HS" keyString:@"value" valueString:@(errorCode)];
52}
53
54- (void)sendEventWithAction:(NSString*)actionName keyString:(NSString*)key valueString:(id)value{
55 [self sendEventWithName:@"HS6.MODULE.NOTIFY" body:@{@"action":actionName,key:value}];
56}
57
58#pragma mark
59#pragma mark - Method
60 RCT_EXPORT_METHOD(init:(nonnull NSString*)userName){
61
62 [iHealthHS6 shareIHHS6Controller];
63
64 userAccount=[userName copy];
65
66 NSLog(@"Set User Succeed!");
67}
68
69/**
70 * set HS6 wifi
71 * Import parameter:
72 * @param password - wifi password.
73 * Return parameters:
74
75 * @param disposeHS6SuccessBlock - set sucess
76
77 * @param disposeHS6FailBlock - set faild
78
79 * @param disposeHS6EndBlock - end set
80
81 * @param disposeHS6ErrorBlock - error code
82 * Error code definition:
83 * refer to “error” : HS6 error instruction.
84 */
85
86/**
87 Set HS6 wifi
88 Import parameter:
89 @param password wifi password.
90
91 Return parameters:
92 @param disposeHS6SuccessBlock set sucess
93 @param disposeHS6FailBlock set faild
94 @param disposeHS6EndBlock end set
95 @param disposeHS6ErrorBlock error code
96 */
97
98RCT_EXPORT_METHOD(setWifi:(nonnull NSString*)ssid :(nonnull NSString*)password){
99
100
101 iHealthHS6 *hs6Controller = [iHealthHS6 shareIHHS6Controller];
102 if (hs6Controller != nil) {
103 [hs6Controller commandSetHS6WithPassWord:password disposeHS6SuccessBlock:^(NSDictionary *deviceInfo) {
104
105 NSMutableArray*deviceArray=[NSMutableArray array];
106
107 [deviceArray addObject:@true];
108
109 NSDictionary *deviceInf = @{@"action":ACTION_HS6_SETWIFI,SETWIFI_RESULT:deviceArray};
110
111 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
112 NSLog(@"WIFI sucess");
113 } disposeHS6FailBlock:^(NSString *failmsg) {
114 NSDictionary *deviceInf = @{@"action":ACTION_HS6_SETWIFI,SETWIFI_RESULT:failmsg};
115 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
116
117 } disposeHS6EndBlock:^(NSDictionary *deviceDic) {
118 NSLog(@"set WIFI over");
119
120 } disposeHS6ErrorBlock:^(NSNumber *error) {
121 NSDictionary *deviceInf = @{@"action":ACTION_HS6_ERROR,HS6_ERROR:[NSNumber numberWithInteger:error]};
122
123 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
124 }];
125 }
126 }
127
128/**
129 Binding QR Device
130 When using the SDK for the first time, measuring method needs to be called to finish user verification.
131
132 @param tempDeviceID device Mac
133 Return parameters:
134 The measurement via SDK will be operated in the case of 1-4, and will be terminated if any of 5-8 occurs. The interface needs to be re-called after analyzing the return parameters.
135 Notice: when a new user registers via SDK, an ‘iHealth disclaimer’ will pop up automatically, and will require the user to agree in order to continue. SDK applications require an Internet connection; there is 10-day trial period if the SDK cannot connect to the internet, the SDK is fully functional during tryout period, but will be terminated without a working internet connection after 10 days.
136 @param result Action = 1;(1:bind sucess 2:full user bind faild 3,:ts error bind faild 4 other),
137 BineNum=10
138 MAC
139 Position = 1;(user in weight number)
140 SetWifi=0
141 Status = 1;(1:binding 2:unbind)
142 TS (time);
143 @param error error code
144 */
145
146RCT_EXPORT_METHOD(bindDeviceHS6:(nonnull NSString*)birthday :(nonnull NSNumber*)weight :(nonnull NSNumber*)height :(nonnull NSNumber*)isSporter :(nonnull NSNumber*)gender :(nonnull NSString*)serialNumber){
147 iHealthHS6 *hs6Controller = [iHealthHS6 shareIHHS6Controller];
148 if (hs6Controller != nil) {
149 HealthUser* healthUser = [[HealthUser alloc] init];
150 healthUser.userAccount = userAccount;
151 healthUser.clientID = HS6_CLIENT_ID;
152 healthUser.clientSecret = HS6_CLIENT_SECRET;
153
154
155 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
156
157 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
158
159 healthUser.birthday=[dateFormatter dateFromString:birthday];
160
161 healthUser.weight=weight;
162
163 healthUser.height=height;
164
165 healthUser.isAthlete=isSporter.intValue;
166
167 healthUser.sex=gender.intValue;
168
169 [hs6Controller cloudCommandUserBinedQRDeviceWithUser:healthUser deviceID:serialNumber binedResult:^(NSArray *resultArray) {
170
171 NSDictionary*deviceDic=[resultArray objectAtIndex:0];
172
173 NSMutableArray*deviceArray=[NSMutableArray array];
174
175 NSDictionary *deviceBackDic = @{BIND_HS6_RESULT:[deviceDic objectForKey:@"Action"],HS6_MODEL:[deviceDic objectForKey:@"Status"],HS6_POSITION:[deviceDic objectForKey:@"Position"],HS6_SETTED_WIFI:[deviceDic objectForKey:@"SetWifi"]};
176
177 [deviceArray addObject:deviceBackDic];
178
179 NSDictionary *deviceInf = @{@"action":ACTION_HS6_BIND,HS6_BIND_EXTRA:deviceArray};
180 NSLog(@"ResultArray%@",resultArray);
181 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
182 } binedError:^(NSString *errorCode) {
183 NSDictionary *deviceInf = @{@"action":ACTION_HS6_ERROR,HS6_ERROR:errorCode};
184 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
185
186 }];
187 }
188}
189/**
190 unBind QR Device
191
192 Import parameter:
193 @param tempUser Properties included: clientID,clientSecret,userAccount,height.
194 clientID & clientSecret: the only identification for users of the SDK, requires registration from iHealth administrator, please email: sdk@ihealthlabs.com.cn for more information.
195 @param serialNumber device Mac
196 Return parameters:
197 @param result Action = 1;(1:bind sucess 2:full user bind faild 3,:ts error bind faild 4 other),
198 MAC
199 Status = 2;(1:binding 2:unbind)
200 TS
201 @param error error code
202 */
203RCT_EXPORT_METHOD(unBindDeviceHS6:(nonnull NSString*)serialNumber){
204
205 iHealthHS6 *hs6Controller = [iHealthHS6 shareIHHS6Controller];
206
207 if (hs6Controller != nil) {
208 HealthUser* healthUser = [[HealthUser alloc] init];
209 healthUser.userAccount = userAccount;
210 healthUser.clientID = HS6_CLIENT_ID;
211 healthUser.clientSecret = HS6_CLIENT_SECRET;
212
213 [hs6Controller cloudCommandUserDisBinedQRDeviceForUser:healthUser withDeviceID:serialNumber disBinedResult:^(NSArray *resultArray) {
214 NSDictionary *deviceInf = @{@"action":ACTION_HS6_UNBIND,HS6_UNBIND_RESULT:resultArray};
215
216 NSLog(@"unBindDeviceHS6:%@",resultArray);
217 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
218
219 } disBinedError:^(NSString *errorCode) {
220 NSDictionary *deviceInf = @{@"action":ACTION_HS6_ERROR,HS6_ERROR:[NSString stringWithFormat:@"%@", errorCode]};
221 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
222 }];
223 }
224}
225
226RCT_EXPORT_METHOD(getToken:(nonnull NSString*)clientId :(nonnull NSString*)clientSecret:(nonnull NSString*)username :(nonnull NSString*)clientPara){
227
228 iHealthHS6 *hs6Controller = [iHealthHS6 shareIHHS6Controller];
229
230 if (hs6Controller != nil) {
231 HealthUser* healthUser = [[HealthUser alloc] init];
232 healthUser.userAccount = username;
233 healthUser.clientID = clientId;
234 healthUser.clientSecret = clientSecret;
235
236
237 [hs6Controller commandHS6GetOpenAPITokenWithUser:healthUser withSuccessBlock:^(NSDictionary*openAPIInfoDic) {
238 NSDictionary *deviceInf = @{@"action":ACTION_HS6_GET_TOKEN,GET_TOKEN_RESULT:openAPIInfoDic};
239 NSLog(@"openAPIInfoDic%@",openAPIInfoDic);
240 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
241 } withErrorBlock:^(NSDictionary *errorCode) {
242
243 if (errorCode!=nil && [errorCode isKindOfClass:[NSDictionary class]]) {
244 NSDictionary *deviceInf = @{@"action":ACTION_HS6_ERROR, HS6_ERROR:[errorCode valueForKey:@"ErrorCode"],HS6_ERROR:[errorCode valueForKey:@"ErrorDescription"]};
245
246 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
247 }
248
249 }];
250 }
251}
252
253/**
254 sync Weight Unit
255 Import parameter:
256 @param tempUser Properties included: clientID,clientSecret,userAccount,serialNub.
257 @param unit IHHS6SDKUnitWeight_kg,IHHS6SDKUnitWeight_lb,IHHS6SDKUnitWeight_oz
258
259 /// kg
260 IHHS6SDKUnitWeight_kg = 0,
261 /// lb
262 IHHS6SDKUnitWeight_lbs =1 ,
263 /// st
264 IHHS6SDKUnitWeight_oz = 2,
265
266 Return parameters:
267 @param unitBlock YES or NO
268 @param errorBlock error code
269 */
270
271RCT_EXPORT_METHOD(setUnit:(nonnull NSString*)username :(nonnull NSNumber*)unitType){
272 iHealthHS6 *hs6Controller = [iHealthHS6 shareIHHS6Controller];
273 if (hs6Controller != nil) {
274 HealthUser* healthUser = [[HealthUser alloc] init];
275 healthUser.userAccount = username;
276 healthUser.clientID = HS6_CLIENT_ID;
277 healthUser.clientSecret = HS6_CLIENT_SECRET;
278
279 [hs6Controller commandHS6WithUser:healthUser withSyncWeightUnit:unitType.intValue withSuccessBlock:^(BOOL syncWeightUnit) {
280 NSDictionary *deviceInf = @{@"action":ACTION_HS6_SET_UNIT,SET_UNIT_RESULT:[NSNumber numberWithBool:syncWeightUnit]};
281 NSLog(@"setUnitResult:%d",syncWeightUnit);
282 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
283
284 } withErrorBlock:^(NSString *errorCode) {
285 NSDictionary *deviceInf = @{@"action":ACTION_HS6_ERROR,HS6_ERROR:errorCode};
286 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
287 }];
288 }
289
290}
291
292/**
293 DownloadHS6Data
294
295 Import parameter:
296 @param tempUser Properties included: clientID,clientSecret,userAccount
297 clientID & clientSecret: the only identification for users of the SDK, requires registration from iHealth administrator, please email: sdk@ihealthlabs.com.cn for more information.
298 @param downloadTS :From 1970, the number of seconds, download data download all data after this point in time.
299 Return parameters:
300 @param getHS6Data AllHS6Data
301
302 @param blockHS6LastTSFromCloud The last timestamp of the data download can be passed in at the next download, and all the data after the timestamp is downloaded.
303
304 @param errorBlock error code 101,102,103,104:networkerror 400:input error 209:The user doesn't exist
305 */
306
307RCT_EXPORT_METHOD(getCloudData:(nonnull NSString*)clientId :(nonnull NSString*)clientSecret :(nonnull NSString*)username :(nonnull NSNumber*)ts :(nonnull NSNumber*)pageSize){
308
309 iHealthHS6 *hs6Controller = [iHealthHS6 shareIHHS6Controller];
310
311 if (hs6Controller != nil) {
312 HealthUser* healthUser = [[HealthUser alloc] init];
313 healthUser.userAccount = username;
314 healthUser.clientID = clientId;
315 healthUser.clientSecret = clientSecret;
316
317 [hs6Controller commandDownloadHS6Data:healthUser withDownloadTS:[ts longValue] withPageSize:[pageSize longValue] withSuccessBlock:^(NSDictionary *dataDic) {
318
319 NSDictionary *deviceInf = @{@"action":ACTION_HS6_GET_CLOUDDATA,HS6_CLOUDDATA:dataDic};
320 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
321
322 } blockHS6LastTSFromCloud:^(NSNumber *lastTS) {
323
324 NSDictionary *deviceInf = @{@"action":ACTION_HS6_GET_CLOUDDATA_LASTTS,HS6_CLOUDDATA_LASTTS:lastTS};
325 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
326
327
328 } withErrorBlock:^(NSNumber *error) {
329
330 NSDictionary *deviceInf = @{@"action":ACTION_HS6_ERROR,HS6_ERROR:error};
331 [self sendEventWithName:EVENT_NOTIFY body:deviceInf];
332
333 }];
334
335
336 }
337}
338
339@end