summaryrefslogtreecommitdiff
path: root/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/iHealthDeviceManagerModule.m
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/iHealthDeviceManagerModule.m')
-rwxr-xr-xlibs/ihealth-sdk/ios/ReactNativeIOSLibrary/iHealthDeviceManagerModule.m1338
1 files changed, 1338 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/iHealthDeviceManagerModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/iHealthDeviceManagerModule.m
new file mode 100755
index 0000000..c402987
--- /dev/null
+++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/iHealthDeviceManagerModule.m
@@ -0,0 +1,1338 @@
1//
2// iHealthDeviceManagerModule.m
3// ReactNativeIOSLibrary
4//
5// Created by daiqingquan on 2016/11/23.
6// Copyright © 2016年 daiqingquan. All rights reserved.
7//
8
9#import "iHealthDeviceManagerModule.h"
10#import "AMHeader.h"
11#import "BPHeader.h"
12#import "HSHeader.h"
13#import "BGHeader.h"
14#import "POHeader.h"
15#import "ECGHeader.h"
16#import "TS28BHeader.h"
17#import "NT13BHeader.h"
18#import "BGMacroFile.h"
19#import "ECGMacroFile.h"
20#import "THV3Macro.h"
21#import "NT13BMacroFile.h"
22#import "IHSDKCloudUser.h"
23#import "ManageDeviceController.h"
24#import "ScanDeviceController.h"
25#import "ConnectDeviceController.h"
26#import <MediaPlayer/MediaPlayer.h>
27
28#import "TS28BModule.h"
29
30#import "BG1S.h"
31
32#import "BG1SController.h"
33
34#import "PO1.h"
35
36#import "PO1Controller.h"
37
38#import "PO1ProfileModule.h"
39
40#import "PT3SBT.h"
41
42#import "PT3SBTController.h"
43
44#import "PT3SBTMacroFile.h"
45
46#define FetchUserInfo @"com.rn.ihealth.dm.userinfo"
47
48#define kEvent_Scan_Device @"event_scan_device"
49#define kEvent_Scan_Finish @"event_scan_finish"
50#define kEvent_Device_Connected @"event_device_connected"
51#define kEvent_Device_Connect_Failed @"event_device_connect_failed"
52#define kEvent_Device_Disconnect @"event_device_disconnect"
53#define kEvent_Authenticate_Result @"event_authenticate_result"
54
55#define kType_AM3S @"AM3S"
56#define kType_AM4 @"AM4"
57#define kType_AM5 @"AM5"
58#define kType_PO3 @"PO3"
59#define kType_BP5 @"BP5"
60#define kType_BP7 @"BP7"
61#define kType_BP3L @"BP3L"
62#define kType_BP5S @"BP5S"
63#define kType_BP7S @"BP7S"
64#define kType_KN550 @"KN550"
65#define kType_HS4 @"HS4"
66#define kType_HS4S @"HS4S"
67#define kType_HS2 @"HS2"
68#define kType_HS2S_PRO @"HS2S Pro"
69#define kType_BG1 @"BG1"
70#define kType_BG5 @"BG5"
71#define kType_BG5S @"BG5S"
72#define kType_ECG3 @"ECG3"
73#define kType_ECG3USB @"ECG3USB"
74#define kType_BTM @"FDIR_V3"
75#define kType_TS28B @"TS28B"
76#define kType_NT13B @"NT13B"
77#define kType_BG1S @"BG1S"
78#define kType_HS2S @"HS2S"
79#define kType_PO1 @"PO1"
80#define kType_PT3SBT @"PT3SBT"
81
82
83@interface iHealthDeviceManagerModule()<TS28BControllerDelegate>
84
85
86@property (strong, nonatomic) TS28BController *ts28bController;
87
88@property (strong, nonatomic) TS28B *ts28b;
89
90@end
91
92@implementation iHealthDeviceManagerModule
93
94RCT_EXPORT_MODULE()
95
96- (NSArray<NSString *> *)supportedEvents {
97 return @[
98 kEvent_Scan_Device,
99 kEvent_Scan_Finish,
100 kEvent_Device_Connected,
101 kEvent_Device_Connect_Failed,
102 kEvent_Device_Disconnect,
103 kEvent_Authenticate_Result,
104 @"event_notify_ts28b",
105 @"event_notify_bg1",
106 @"action_connect_result_for_bg1"
107 ];
108}
109
110+ (BOOL)requiresMainQueueSetup {
111 return YES;
112}
113
114#pragma mark - constantsToExport
115
116- (NSDictionary *)constantsToExport{
117 return @{
118 @"AM3S" :kType_AM3S,
119 @"AM4" :kType_AM4,
120 @"AM5" :kType_AM5,
121 @"PO3":kType_PO3,
122 @"PO3M":kType_PO3,
123 @"BP5":kType_BP5,
124 @"BP7":kType_BP7,
125 @"BP3L" :kType_BP3L,
126 @"BP5S" : kType_BP5S,
127 @"BP7S" : kType_BP7S,
128 @"KN550":kType_KN550,
129 @"HS4S" :kType_HS4,
130 @"HS4" :kType_HS4,
131 @"HS2" :kType_HS2,
132 @"BG1":kType_BG1,
133 @"BG5":kType_BG5,
134 @"BG5S":kType_BG5S,
135 @"ECG3":kType_ECG3,
136 @"ECG3USB":kType_ECG3USB,
137 @"BTM":kType_BTM,
138 @"NT13B":kType_NT13B,
139 @"TS28B":kType_TS28B,
140 @"BG1S":kType_BG1S,
141 @"HS2S":kType_HS2S,
142 @"HS2S Pro":kType_HS2S_PRO,
143 @"PO1":kType_PO1,
144 @"PT3SBT":kType_PT3SBT,
145 @"Event_Scan_Device":kEvent_Scan_Device,
146 @"Event_Scan_Finish":kEvent_Scan_Finish,
147 @"Event_Device_Connected":kEvent_Device_Connected,
148 @"Event_Device_Connect_Failed":kEvent_Device_Connect_Failed,
149 @"Event_Device_Disconnect":kEvent_Device_Disconnect,
150 @"Event_Authenticate_Result":kEvent_Authenticate_Result,
151 };
152};
153
154#pragma mark
155#pragma mark - Init
156-(id)init{
157 NSLog(@"iHealthScanner: *** iHealthDeviceManagerModule init CALLED ***");
158 if (self = [super init]){
159 NSLog(@"iHealthScanner: *** Registering NSNotification observers ***");
160 [ScanDeviceController commandGetInstance];
161 // AM3S
162 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:AM3SDiscover object:nil];
163 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:AM3SConnectFailed object:nil];
164 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:AM3SConnectNoti object:nil];
165 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:AM3SDisConnectNoti object:nil];
166 // AM4
167 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:AM4Discover object:nil];
168 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:AM4ConnectFailed object:nil];
169 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:AM4ConnectNoti object:nil];
170 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:AM4DisConnectNoti object:nil];
171
172 //AM5
173
174 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:AM5Discover object:nil];
175
176 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:AM5ConnectFailed object:nil];
177
178 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:AM5ConnectNoti object:nil];
179
180 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:AM5DisConnectNoti object:nil];
181
182 // PO3
183 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:PO3Discover object:nil];
184 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:PO3ConnectFailed object:nil];
185 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:PO3ConnectNoti object:nil];
186 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:PO3DisConnectNoti object:nil];
187 // BP5
188 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BP5ConnectNoti object:nil];
189 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BP5DisConnectNoti object:nil];
190 // BP7
191 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BP7ConnectNoti object:nil];
192 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BP7DisConnectNoti object:nil];
193 //BP3L
194 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:BP3LDiscover object:nil];
195 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:BP3LConnectFailed object:nil];
196 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BP3LConnectNoti object:nil];
197 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BP3LDisConnectNoti object:nil];
198
199 //BP5S
200 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:BP5SDiscover object:nil];
201 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:BP5SConnectFailed object:nil];
202 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BP5SConnectNoti object:nil];
203 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BP5SDisConnectNoti object:nil];
204
205 //BP7S
206 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:BP7SDiscover object:nil];
207 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BP7SConnectNoti object:nil];
208 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BP7SDisConnectNoti object:nil];
209 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:BP7SConnectFailed object:nil];
210
211 //KN550BT
212 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:KN550BTDiscover object:nil];
213 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:KN550BTConnectNoti object:nil];
214 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:KN550BTDisConnectNoti object:nil];
215 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:KN550BTConnectFailed object:nil];
216 // HS4S
217 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:HS4Discover object:nil];
218 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:HS4ConnectFailed object:nil];
219 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:HS4ConnectNoti object:nil];
220 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:HS4DisConnectNoti object:nil];
221 // HS2
222 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:HS2Discover object:nil];
223 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:HS2ConnectFailed object:nil];
224 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:HS2ConnectNoti object:nil];
225 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:HS2DisConnectNoti object:nil];
226
227
228 // HS2S
229 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:HS2SDiscover object:nil];
230 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:HS2SConnectFailed object:nil];
231 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:HS2SConnectNoti object:nil];
232 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:HS2SDisConnectNoti object:nil];
233
234 //BG1
235 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(bg1Discover:) name:kNotificationNameNeedAudioPermission object:nil];
236 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(bg1Connect:) name:kNotificationNameAudioDeviceInsert object:nil];
237 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceBG1Disconnect:) name:kNotificationNameBG1DidDisConnect object:nil];
238 //BG5
239 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BG5ConnectNoti object:nil];
240 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BG5DisConnectNoti object:nil];
241
242 // BG5S
243 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:kNotificationNameBG5SDidDiscover object:nil];
244 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:kNotificationNameBG5SConnectFail object:nil];
245 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:kNotificationNameBG5SConnectSuccess object:nil];
246 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:kNotificationNameBG5SDidDisConnect object:nil];
247
248 //ECG3
249 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:ECG3Discover object:nil];
250 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:ECG3ConnectFailed object:nil];
251 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:ECG3ConnectNoti object:nil];
252 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:ECG3DisConnectNoti object:nil];
253
254 //ECG3USB
255 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:ECGUSBConnectNoti object:nil];
256 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:ECGUSBDisConnectNoti object:nil];
257
258 //BTM(THV3)
259 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:THV3Discover object:nil];
260 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:THV3ConnectFailed object:nil];
261 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:THV3ConnectNoti object:nil];
262 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:THV3DisConnectNoti object:nil];
263 //NT13B
264
265 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:NT13BDiscover object:nil];
266 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:NT13BConnectFailed object:nil];
267 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:NT13BConnectNoti object:nil];
268 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:NT13BDisConnectNoti object:nil];
269
270 //TS28B
271
272
273
274 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(disconnectTS28B) name:@"disconnectTS28B" object:nil];
275 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getAllTS28BConnectedDevices) name:@"getAllTS28BConnectedDevices" object:nil];
276
277
278 //BG1S
279
280 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:BG1SDiscover object:nil];
281 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:BG1SConnectFailed object:nil];
282 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BG1SConnectNoti object:nil];
283 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BG1SDisConnectNoti object:nil];
284 // PO1
285 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:PO1Discover object:nil];
286 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:PO1ConnectFailed object:nil];
287 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:PO1ConnectNoti object:nil];
288 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:PO1DisConnectNoti object:nil];
289 // PT3SBT
290 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:PT3SBTDiscover object:nil];
291 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:PT3SBTConnectFailed object:nil];
292 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:PT3SBTConnectNoti object:nil];
293 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:PT3SBTDisConnectNoti object:nil];
294
295 [AM3Controller shareIHAM3Controller];
296 [AM3SController_V2 shareIHAM3SController];
297 [AM4Controller shareIHAM4Controller];
298 [AM5Controller shareAM5Controller];
299 [BP3LController shareBP3LController];
300 [BP5Controller shareBP5Controller];
301 [BP7Controller shareBP7Controller];
302 [BP5SController sharedController];
303 [BG5Controller shareIHBg5Controller];
304 [BG5SController sharedController];
305 [ECG3Controller shareECG3Controller];
306 [ECG3USBController shareECG3USBController];
307 [HS4Controller shareIHHs4Controller];
308 [HS2Controller shareIHHs2Controller];
309 [HS2SController shareIHHS2SController];
310 [THV3Controller sharedController];
311 [NT13BController shareIHNT13BController];
312 [BG1SController shareIHBG1SController];
313 [PO1Controller shareIHPO1Controller];
314 [PT3SBTController shareIHPT3SBTController];
315
316 }
317 return self;
318}
319
320- (void)dealloc{
321 [[NSNotificationCenter defaultCenter]removeObserver:self];
322}
323
324#pragma mark -
325
326-(void)disconnectTS28B{
327
328 [self.ts28bController disconnectDevice:self.ts28b];
329
330}
331-(void)getAllTS28BConnectedDevices{
332
333 if (self.ts28b==nil) {
334 return;
335 }
336
337 NSDictionary* deviceInfo = @{@"event_notify_ts28b":@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":self.ts28b.serialNumber};
338
339 [self sendEventWithName:@"event_notify_ts28b" body:deviceInfo];
340}
341
342- (NSString*)serialNumebr:(NSDictionary*)userInfo{
343 if (!userInfo){
344 return nil;
345 }
346 NSString* serialNumber = userInfo[@"SerialNumber"];
347 NSString* deviceId = userInfo[@"ID"];
348 if (serialNumber && serialNumber.length > 0){
349 return serialNumber;
350 } else if (deviceId && deviceId.length > 0){
351 return deviceId;
352 }
353 return nil;
354}
355
356#pragma mark - Notification
357
358#pragma mark - BG1
359-(void)bg1Discover:(NSNotification*)info {
360
361
362 // NSDictionary* deviceInfo = @{@"mac":@"",@"type":@"BG1"};
363 // [self sendEventWithName:kEvent_Scan_Device body:deviceInfo];
364
365}
366
367-(void)bg1Connect:(NSNotification*)info {
368
369 [[MPMusicPlayerController applicationMusicPlayer] setVolume:1.0f];
370 NSDictionary* deviceInfo = @{@"mac":@"",@"type":@"BG1"};
371 [self sendEventWithName:kEvent_Scan_Device body:deviceInfo];
372
373
374 // NSDictionary* deviceInfo = @{@"mac":@"",@"type":@"BG1"};
375 // [self sendEventWithName:kEvent_Device_Connected body:deviceInfo];
376
377 BG1*myBG1=[[BG1Controller shareBG1Controller] getCurrentBG1Instance];
378
379 [myBG1 commandBG1DeviceModel:@0 withDiscoverBlock:^{
380
381 } withDiscoverBlock:^(NSDictionary *idpsDic) {
382
383 bg1IdpsDic = [NSDictionary dictionaryWithDictionary:idpsDic];
384
385 } withConnectBlock:^{
386
387 NSString *bg1Mac = @"";
388 if (bg1IdpsDic[@"SerialNumber"] != nil) {
389 bg1Mac = bg1IdpsDic[@"SerialNumber"];
390 }
391 NSDictionary* deviceInfo = @{@"mac":bg1Mac,@"type":@"BG1"};
392 [self sendEventWithName:kEvent_Device_Connected body:deviceInfo];
393
394 } withErrorBlock:^(BG1Error errorID) {
395
396 NSDictionary* deviceInfo = @{@"mac":@"",@"action":@"action_measure_error_for_bg1",@"action_measure_error_for_bg1":[NSNumber numberWithInt:errorID]};
397 [self sendEventWithName:@"event_notify_bg1" body:deviceInfo];
398
399 }];
400
401}
402
403-(void)deviceBG1Disconnect:(NSNotification*)info {
404
405 NSDictionary* deviceInfo = @{@"mac":@"",@"type":kType_BG1};
406 [self sendEventWithName:kEvent_Device_Disconnect body:deviceInfo];
407}
408
409#pragma mark - 发现BLE设备
410-(void)deviceDiscover:(NSNotification*)info {
411
412 NSLog(@"Native: device discover %@", info);
413
414 NSDictionary* userInfo = [info userInfo];
415 NSString* deviceName = userInfo[@"DeviceName"];
416
417 NSDictionary *deviceNameForType = @{
418 @"AM3S" :kType_AM3S,
419 @"AM4" :kType_AM4,
420 @"AM5" :kType_AM5,
421 @"PO3":kType_PO3,
422 @"PO3M":kType_PO3,
423 @"BP3L" :kType_BP3L,
424 @"BP5S" : kType_BP5S,
425 @"BP7S" : kType_BP7S,
426 @"KN-550BT":kType_KN550,
427 @"KN550":kType_KN550,
428 @"HS4S" :kType_HS4,
429 @"HS4" :kType_HS4,
430 @"HS2" :kType_HS2,
431 @"ECG3":kType_ECG3,
432 @"FDTH":kType_BTM,
433 @"BG5S":kType_BG5S,
434 @"NT13B":kType_NT13B,
435 @"TS28B":kType_TS28B,
436 @"BG1S":kType_BG1S,
437 @"HS2S":kType_HS2S,
438 @"PO1":kType_PO1,
439 @"PT3SBT":kType_PT3SBT,
440 };
441
442 if (deviceNameForType[deviceName] && [self serialNumebr:userInfo]){
443 NSString *sn = [self serialNumebr:userInfo];
444 [self sendEventWithName:kEvent_Scan_Device body:@{@"mac":sn,@"type":deviceNameForType[deviceName]}];
445 }
446}
447
448#pragma mark 连接成功 BT\BLE都用这个通知
449- (BOOL)isIAPDevice:(NSString*)deviceName{
450 NSArray *array = @[@"BP5",@"BP7",@"BG5",@"ECG"];
451 if (deviceName && [array containsObject:deviceName]){
452 return YES;
453 } else {
454 return NO;
455 }
456}
457-(void)deviceConnect:(NSNotification*)info {
458
459 NSDictionary* userInfo = [info userInfo];
460 NSLog(@"连接成功:%@",userInfo);
461 NSString* deviceName = userInfo[@"DeviceName"];
462
463 NSString* protocolString = userInfo[@"ProtocolString"];
464
465 if ([protocolString isEqualToString:@"NT13B_Protocol"]) {
466 deviceName=@"NT13B";
467 }
468
469 NSDictionary *deviceNameForType = @{
470 @"AM3S" :kType_AM3S,
471 @"AM4" :kType_AM4,
472 @"AM5" :kType_AM5,
473 @"PO3":kType_PO3,
474 @"PO3M":kType_PO3,
475 @"BP3L" :kType_BP3L,
476 @"BP5S" : kType_BP5S,
477 @"BP7S" : kType_BP7S,
478 @"KN-550BT":kType_KN550,
479 @"KN550":kType_KN550,
480 @"HS4S" :kType_HS4,
481 @"HS4" :kType_HS4,
482 @"HS2" :kType_HS2,
483 @"FDTH":kType_BTM,
484 @"BP5":kType_BP5,
485 @"BP7":kType_BP7,
486 @"BG5":kType_BG5,
487 @"BG5S":kType_BG5S,
488 @"ECG3":kType_ECG3,
489 @"ECG":kType_ECG3USB,// ECG3USB的连接通知里使用的设备名称是ECG,
490 @"NT13B":kType_NT13B,
491 @"TS28B":kType_TS28B,
492 @"BG1S":kType_BG1S,
493 @"HS2S":kType_HS2S,
494 @"HS2S Pro":kType_HS2S_PRO,
495 @"PO1":kType_PO1,
496 @"PT3SBT":kType_PT3SBT,
497 };
498
499 if (deviceNameForType[deviceName] && [self serialNumebr:userInfo]){
500 NSString *sn = [self serialNumebr:userInfo];
501 if ([self isIAPDevice:deviceName]){
502 [self sendEventWithName:kEvent_Scan_Device body:@{@"mac":sn,@"type":deviceNameForType[deviceName]}];
503 }
504 [self sendEventWithName:kEvent_Device_Connected body:@{@"mac":sn,@"type":deviceNameForType[deviceName]}];
505 }
506}
507#pragma mark 连接断开 BT\BLE都用这个通知
508-(void)deviceDisconnect:(NSNotification*)info {
509 NSDictionary* userInfo = [info userInfo];
510 NSString* deviceName = userInfo[@"DeviceName"];
511
512 NSString* protocolString = userInfo[@"ProtocolString"];
513
514 if ([protocolString isEqualToString:@"NT13B_Protocol"]) {
515 deviceName=@"NT13B";
516 }
517
518 if ([protocolString isEqualToString:@"com.jiuan.PO1"]) {
519 deviceName=@"PO1";
520 }
521
522 NSDictionary *deviceNameForType = @{
523 @"AM3S" :kType_AM3S,
524 @"AM4" :kType_AM4,
525 @"AM5" :kType_AM5,
526 @"PO3":kType_PO3,
527 @"PO3M":kType_PO3,
528 @"BP3L" :kType_BP3L,
529 @"BP5S" : kType_BP5S,
530 @"BP7S" : kType_BP7S,
531 @"KN-550BT":kType_KN550,
532 @"KN550":kType_KN550,
533 @"HS4S" :kType_HS4,
534 @"HS4" :kType_HS4,
535 @"HS2" :kType_HS2,
536 @"FDTH":kType_BTM,
537 @"BP5":kType_BP5,
538 @"BP7":kType_BP7,
539 @"BG5":kType_BG5,
540 @"BG5S":kType_BG5S,
541 @"ECG3":kType_ECG3,
542 @"ECG":kType_ECG3USB,// ECG3USB的连接通知里使用的设备名称是ECG,
543 @"NT13B":kType_NT13B,
544 @"TS28B":kType_TS28B,
545 @"BG1S":kType_BG1S,
546 @"HS2S":kType_HS2S,
547 @"HS2S Pro":kType_HS2S_PRO,
548 @"PO1":kType_PO1,
549 @"PT3SBT":kType_PT3SBT,
550 };
551
552 if (deviceNameForType[deviceName] && [self serialNumebr:userInfo]){
553 NSString *sn = [self serialNumebr:userInfo];
554 [self sendEventWithName:kEvent_Device_Disconnect body:@{@"mac":sn,@"type":deviceNameForType[deviceName]}];
555 }
556}
557#pragma mark - 连接失败,BLE设备
558-(void)deviceConnectFailed:(NSNotification*)info {
559 NSDictionary* userInfo = [info userInfo];
560 NSString* deviceName = userInfo[@"DeviceName"];
561
562 NSString* protocolString = userInfo[@"ProtocolString"];
563
564 if ([protocolString isEqualToString:@"NT13B_Protocol"]) {
565 deviceName=@"NT13B";
566 }
567
568 NSDictionary *deviceNameForType = @{
569 @"AM3S" :kType_AM3S,
570 @"AM4" :kType_AM4,
571 @"AM5" :kType_AM5,
572 @"PO3":kType_PO3,
573 @"PO3M":kType_PO3,
574 @"BP3L" :kType_BP3L,
575 @"BP5S" : kType_BP5S,
576 @"BG5S" :kType_BG5S,
577 @"BP7S" : kType_BP7S,
578 @"KN-550BT":kType_KN550,
579 @"KN550":kType_KN550,
580 @"HS4S" :kType_HS4,
581 @"HS4" :kType_HS4,
582 @"HS2" :kType_HS2,
583 @"FDTH":kType_BTM,
584 @"ECG3":kType_ECG3,
585 @"NT13B":kType_NT13B,
586 @"TS28B":kType_TS28B,
587 @"BG1S":kType_BG1S,
588 @"HS2S":kType_HS2S,
589 @"HS2S Pro":kType_HS2S_PRO,
590 @"PO1":kType_PO1,
591 @"PT3SBT":kType_PT3SBT,
592 };
593
594 if (deviceNameForType[deviceName] && [self serialNumebr:userInfo]){
595 NSString *sn = [self serialNumebr:userInfo];
596 [self sendEventWithName:kEvent_Device_Connect_Failed body:@{@"mac":sn,@"type":deviceNameForType[deviceName]}];
597 }
598}
599
600#pragma mark - Method
601
602RCT_EXPORT_METHOD(sdkAuthWithLicense:(nonnull NSString *)license){
603
604
605 NSArray * arr = [license componentsSeparatedByString:@"."];
606
607
608 NSString*licenseName=[NSString stringWithFormat:@"%@",[arr objectAtIndex:0]];
609
610
611 NSString *filePath = [[NSBundle mainBundle] pathForResource:licenseName ofType:@"pem"];
612
613
614 NSData*data = [NSData dataWithContentsOfFile:filePath];
615
616
617
618 if (data!=nil) {
619
620 [[IHSDKCloudUser commandGetSDKUserInstance] commandSDKUserValidationWithLicense:data UserDeviceAccess:^(NSArray *DeviceAccessArray) {
621
622 NSLog(@"DeviceAccessArray :%@",DeviceAccessArray);
623
624 } UserValidationSuccess:^(UserAuthenResult result) {
625
626 if (result==UserAuthen_LoginSuccess || result==UserAuthen_RegisterSuccess|| result==UserAuthen_TrySuccess ) {
627 [self sendEventWithName:kEvent_Authenticate_Result body:@{@"access":@1}];
628 }else{
629
630 [self sendEventWithName:kEvent_Authenticate_Result body:@{@"access":@0}];
631
632 }
633
634 } DisposeErrorBlock:^(UserAuthenResult errorID) {
635
636 [self sendEventWithName:kEvent_Authenticate_Result body:@{@"access":@0}];
637
638
639
640
641
642 }];
643
644 }else{
645
646
647 [self sendEventWithName:kEvent_Authenticate_Result body:@{@"access":@0}];
648
649 }
650
651
652
653
654}
655
656-(void)ensureInitialized {
657 static dispatch_once_t onceToken;
658 dispatch_once(&onceToken, ^{
659 NSLog(@"iHealthScanner: *** ensureInitialized - registering observers ***");
660 [ScanDeviceController commandGetInstance];
661
662 // AM3S
663 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:AM3SDiscover object:nil];
664 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:AM3SConnectFailed object:nil];
665 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:AM3SConnectNoti object:nil];
666 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:AM3SDisConnectNoti object:nil];
667 // AM4
668 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:AM4Discover object:nil];
669 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:AM4ConnectFailed object:nil];
670 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:AM4ConnectNoti object:nil];
671 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:AM4DisConnectNoti object:nil];
672 // AM5
673 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:AM5Discover object:nil];
674 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:AM5ConnectFailed object:nil];
675 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:AM5ConnectNoti object:nil];
676 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:AM5DisConnectNoti object:nil];
677 // PO3
678 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:PO3Discover object:nil];
679 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:PO3ConnectFailed object:nil];
680 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:PO3ConnectNoti object:nil];
681 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:PO3DisConnectNoti object:nil];
682 // BP5
683 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BP5ConnectNoti object:nil];
684 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BP5DisConnectNoti object:nil];
685 // BP7
686 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BP7ConnectNoti object:nil];
687 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BP7DisConnectNoti object:nil];
688 // BP3L
689 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:BP3LDiscover object:nil];
690 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:BP3LConnectFailed object:nil];
691 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BP3LConnectNoti object:nil];
692 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BP3LDisConnectNoti object:nil];
693 // BP5S
694 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:BP5SDiscover object:nil];
695 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:BP5SConnectFailed object:nil];
696 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BP5SConnectNoti object:nil];
697 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BP5SDisConnectNoti object:nil];
698 // BP7S
699 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:BP7SDiscover object:nil];
700 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BP7SConnectNoti object:nil];
701 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BP7SDisConnectNoti object:nil];
702 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:BP7SConnectFailed object:nil];
703 // KN550BT
704 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:KN550BTDiscover object:nil];
705 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:KN550BTConnectNoti object:nil];
706 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:KN550BTDisConnectNoti object:nil];
707 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:KN550BTConnectFailed object:nil];
708 // HS4S
709 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:HS4Discover object:nil];
710 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:HS4ConnectFailed object:nil];
711 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:HS4ConnectNoti object:nil];
712 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:HS4DisConnectNoti object:nil];
713 // HS2
714 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:HS2Discover object:nil];
715 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:HS2ConnectFailed object:nil];
716 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:HS2ConnectNoti object:nil];
717 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:HS2DisConnectNoti object:nil];
718 // HS2S
719 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:HS2SDiscover object:nil];
720 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:HS2SConnectFailed object:nil];
721 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:HS2SConnectNoti object:nil];
722 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:HS2SDisConnectNoti object:nil];
723 // BG1
724 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(bg1Discover:) name:kNotificationNameNeedAudioPermission object:nil];
725 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(bg1Connect:) name:kNotificationNameAudioDeviceInsert object:nil];
726 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceBG1Disconnect:) name:kNotificationNameBG1DidDisConnect object:nil];
727 // BG5
728 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BG5ConnectNoti object:nil];
729 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BG5DisConnectNoti object:nil];
730 // BG5S
731 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:kNotificationNameBG5SDidDiscover object:nil];
732 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:kNotificationNameBG5SConnectFail object:nil];
733 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:kNotificationNameBG5SConnectSuccess object:nil];
734 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:kNotificationNameBG5SDidDisConnect object:nil];
735 // ECG3
736 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:ECG3Discover object:nil];
737 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:ECG3ConnectFailed object:nil];
738 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:ECG3ConnectNoti object:nil];
739 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:ECG3DisConnectNoti object:nil];
740 // ECG3USB
741 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:ECGUSBConnectNoti object:nil];
742 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:ECGUSBDisConnectNoti object:nil];
743 // BTM(THV3)
744 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:THV3Discover object:nil];
745 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:THV3ConnectFailed object:nil];
746 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:THV3ConnectNoti object:nil];
747 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:THV3DisConnectNoti object:nil];
748 // NT13B
749 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:NT13BDiscover object:nil];
750 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:NT13BConnectFailed object:nil];
751 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:NT13BConnectNoti object:nil];
752 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:NT13BDisConnectNoti object:nil];
753 // TS28B
754 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(disconnectTS28B) name:@"disconnectTS28B" object:nil];
755 // PO1
756 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:PO1Discover object:nil];
757 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:PO1ConnectFailed object:nil];
758 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:PO1ConnectNoti object:nil];
759 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:PO1DisConnectNoti object:nil];
760 // PT3SBT
761 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:PT3SBTDiscover object:nil];
762 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:PT3SBTConnectFailed object:nil];
763 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:PT3SBTConnectNoti object:nil];
764 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:PT3SBTDisConnectNoti object:nil];
765 // BG1S
766 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDiscover:) name:BG1SDiscover object:nil];
767 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnectFailed:) name:BG1SConnectFailed object:nil];
768 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceConnect:) name:BG1SConnectNoti object:nil];
769 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceDisconnect:) name:BG1SDisConnectNoti object:nil];
770
771 NSLog(@"iHealthScanner: *** ensureInitialized DONE ***");
772 });
773}
774
775RCT_EXPORT_METHOD(startDiscovery:(nonnull NSString *)deviceType){
776 [self ensureInitialized];
777 NSLog(@"iHealthScanner: startDiscovery called with type=%@", deviceType);
778 if ([deviceType isEqualToString:kType_BP5]){
779
780 NSArray*bp5array = [[BP5Controller shareBP5Controller] getAllCurrentBP5Instace];
781 if (bp5array.count) {
782 for (int i=0; i<bp5array.count; i++) {
783 BP5*mybp5=[bp5array objectAtIndex:i];
784 NSDictionary* deviceInfo = [[NSDictionary alloc]init];
785 deviceInfo = @{@"mac":mybp5.serialNumber,@"type":kType_BP5};
786 [self sendEventWithName:kEvent_Scan_Device body:deviceInfo];
787 }
788 }
789 }else if ([deviceType isEqualToString:kType_BP7]){
790
791 NSArray*bp7array = [[BP7Controller shareBP7Controller] getAllCurrentBP7Instace];
792 if (bp7array.count) {
793 for (int i=0; i<bp7array.count; i++) {
794 BP7*mybp7=[bp7array objectAtIndex:i];
795 NSDictionary* deviceInfo = [[NSDictionary alloc]init];
796 deviceInfo = @{@"mac":mybp7.serialNumber,@"type":kType_BP7};
797 [self sendEventWithName:kEvent_Scan_Device body:deviceInfo];
798 }
799 }
800 } else if ([deviceType isEqualToString:kType_BG1]){
801
802 [[BG1Controller shareBG1Controller] initBGAudioModule];
803 } else if ([deviceType isEqualToString:kType_BG5]){
804
805 NSArray*bg5array = [[BG5Controller shareIHBg5Controller] getAllCurrentBG5Instace];
806 if (bg5array.count) {
807 for (int i=0; i<bg5array.count; i++) {
808 BG5*mybg5=[bg5array objectAtIndex:i];
809 NSDictionary* deviceInfo = [[NSDictionary alloc]init];
810 deviceInfo = @{@"mac":mybg5.serialNumber,@"type":kType_BG5};
811 [self sendEventWithName:kEvent_Scan_Device body:deviceInfo];
812 }
813 }
814 } else if ([deviceType isEqualToString:kType_ECG3USB]){
815
816 ECG3USB*myecg3 = [[ECG3USBController shareECG3USBController] getCurrentECG3USBInstace];
817 if (myecg3!=nil) {
818 NSDictionary* deviceInfo = [[NSDictionary alloc]init];
819 deviceInfo = @{@"mac":myecg3.serialNumber,@"type":kType_ECG3USB};
820 [self sendEventWithName:kEvent_Scan_Device body:deviceInfo];
821 }
822 } else if ([deviceType isEqualToString:kType_AM3S]){
823
824 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_AM3S];
825 } else if ([deviceType isEqualToString:kType_AM4]){
826
827 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_AM4];
828
829 } else if ([deviceType isEqualToString:kType_AM5]){
830
831 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_AM5];
832
833 } else if ([deviceType isEqualToString:kType_BP3L]){
834
835 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_BP3L];
836 } else if ([deviceType isEqualToString:kType_BP5S]){
837
838 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_BP5S];
839 } else if ([deviceType isEqualToString:kType_BP7S]){
840
841 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_BP7S];
842 } else if ([deviceType isEqualToString:kType_KN550]){
843
844 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_KN550BT];
845 } else if ([deviceType isEqualToString:kType_HS4] ||[deviceType isEqualToString:kType_HS4S]){
846
847 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_HS4];
848 } else if ([deviceType isEqualToString:kType_HS2]){
849
850 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_HS2];
851 }else if ([deviceType isEqualToString:kType_PO3]){
852
853 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_PO3];
854
855 } else if ([deviceType isEqualToString:kType_BTM]){
856
857 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_THV3];
858
859 }else if ([deviceType isEqualToString:kType_ECG3]){
860
861 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_ECG3];
862
863 }else if ([deviceType isEqualToString:kType_BG5S]){
864
865 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_BG5S];
866
867 }
868 else if ([deviceType isEqualToString:kType_NT13B]){
869
870 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_NT13B];
871
872 }else if ([deviceType isEqualToString:kType_BG1S]){
873
874 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_BG1S];
875
876 }else if ([deviceType isEqualToString:kType_HS2S]){
877
878 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_HS2S];
879
880 }
881
882 else if ([deviceType isEqualToString:kType_TS28B]){
883
884 self.ts28bController = [TS28BController sharedController];
885 self.ts28bController.delegate = self;
886 [self.ts28bController startScan];
887
888 }else if ([deviceType isEqualToString:kType_PO1]){
889
890 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_PO1];
891
892 }else if ([deviceType isEqualToString:kType_PT3SBT]){
893
894 [[ScanDeviceController commandGetInstance] commandScanDeviceType:HealthDeviceType_PT3SBT];
895
896 } else {
897 NSLog(@"iHealthScanner: unknown device type '%@', ignoring", deviceType);
898 }
899}
900
901
902#pragma mark - TS28B delegate
903
904- (void)controller:(TS28BController *)controller didDiscoverDevice:(TS28B *)device{
905 NSLog(@"搜索到设备的代理");
906
907 [self.ts28bController connectDevice:device];
908
909 [self sendEventWithName:kEvent_Scan_Device body:@{@"mac":device.serialNumber,@"type":@"TS28B"}];
910
911
912
913}
914- (void)controller:(TS28BController *)controller didConnectSuccessDevice:(TS28B *)device{
915 NSLog(@"连接成功的代理");
916// self.connectedDevice = device;
917// 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]);
918
919 self.ts28b=device;
920
921 [self sendEventWithName:kEvent_Device_Connected body:@{@"mac":device.serialNumber,@"type":@"TS28B"}];
922}
923- (void)controller:(TS28BController *)controller didConnectFailDevice:(TS28B *)device{
924 NSLog(@"连接失败的代理");
925// self.recordTextView.text = @"连接失败";
926 [self sendEventWithName:kEvent_Device_Connect_Failed body:@{@"mac":device.peripheral.identifier,@"type":@"TS28B"}];
927}
928- (void)controller:(TS28BController *)controller didDisconnectDevice:(TS28B *)device{
929 NSLog(@"断开连接的代理");
930// self.recordTextView.text = @"连接断开";
931
932
933 [self sendEventWithName:kEvent_Device_Disconnect body:@{@"mac":device.serialNumber,@"type":@"TS28B"}];
934}
935- (void)controller:(TS28BController *)controller device:(TS28B *)device didUpdateTemperature:(float)value temperatureUnit:(TemperatureUnit)unit measureDate:(NSDate *)date measureLocation:(TemperatureType)type{
936
937// self.valueLabel.text = [NSString stringWithFormat:@"%.1f %@",value,(unit == TemperatureUnit_C)?@"C":@"F"];
938}
939
940
941
942RCT_EXPORT_METHOD(stopDiscovery){
943
944 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_AM3S];
945
946 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_AM4];
947
948 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_AM5];
949
950 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_BP3L];
951
952 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_BP5S];
953
954 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_BP7S];
955
956 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_KN550BT];
957
958 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_PO3];
959
960 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_HS4];
961
962 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_HS2];
963
964 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_ECG3];
965
966 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_ECG3];
967
968 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_THV3];
969
970 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_BG5S];
971
972 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_NT13B];
973
974 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_BG1S];
975
976
977 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_HS2S];
978
979 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_PO1];
980
981 [[ScanDeviceController commandGetInstance] commandStopScanDeviceType:HealthDeviceType_PT3SBT];
982
983 [self sendEventWithName:kEvent_Scan_Finish body:nil];
984}
985
986RCT_EXPORT_METHOD(connectDevice:(nonnull NSString *)mac type:(nonnull NSString *)deviceType){
987 if ([deviceType isEqualToString:kType_BP5]){
988
989 NSArray*bp5array = [[BP5Controller shareBP5Controller] getAllCurrentBP5Instace];
990 if (bp5array.count) {
991 for (int i=0; i<bp5array.count; i++) {
992 BP5*mybp5=[bp5array objectAtIndex:i];
993 NSDictionary* deviceInfo = @{@"mac":mybp5.serialNumber,@"type":kType_BP5};
994 [self sendEventWithName:kEvent_Device_Connected body:deviceInfo];
995 }
996 }
997
998 }else if ([deviceType isEqualToString:kType_BP7]){
999
1000 NSArray*bp7array = [[BP7Controller shareBP7Controller] getAllCurrentBP7Instace];
1001 if (bp7array.count) {
1002 for (int i=0; i<bp7array.count; i++) {
1003 BP7*mybp7=[bp7array objectAtIndex:i];
1004 NSDictionary* deviceInfo = @{@"mac":mybp7.serialNumber,@"type":kType_BP7};
1005 [self sendEventWithName:kEvent_Device_Connected body:deviceInfo];
1006 }
1007 }
1008
1009
1010 } else if ([deviceType isEqualToString:kType_BG1]){
1011
1012 BG1*myBG1=[[BG1Controller shareBG1Controller] getCurrentBG1Instance];
1013
1014 [myBG1 commandBG1DeviceModel:@0 withDiscoverBlock:^{
1015
1016 } withDiscoverBlock:^(NSDictionary *idpsDic) {
1017
1018 bg1IdpsDic = [NSDictionary dictionaryWithDictionary:idpsDic];
1019
1020 NSString *bg1Mac = @"";
1021 if (bg1IdpsDic[@"SerialNumber"] != nil) {
1022 bg1Mac = bg1IdpsDic[@"SerialNumber"];
1023 }
1024 NSDictionary*idpsDics=[[NSDictionary alloc] initWithObjectsAndKeys:[bg1IdpsDic valueForKey:@"FW"],@"FirmWare",[bg1IdpsDic valueForKey:@"HD"],@"HardWare",[bg1IdpsDic valueForKey:@"SerialNumber"],@"DeviceId",nil];
1025 NSDictionary* deviceInfo = @{@"mac":bg1Mac,@"type":@"BG1",@"description":@"Success.",@"connect_result_for_bg1":@0,@"idps":idpsDics};
1026 [self sendEventWithName:@"action_connect_result_for_bg1" body:deviceInfo];
1027
1028 } withConnectBlock:^{
1029
1030 NSString *bg1Mac = @"";
1031 if (bg1IdpsDic[@"SerialNumber"] != nil) {
1032 bg1Mac = bg1IdpsDic[@"SerialNumber"];
1033 }
1034 NSDictionary* deviceInfo = @{@"mac":bg1Mac,@"type":@"BG1"};
1035 [self sendEventWithName:kEvent_Device_Connected body:deviceInfo];
1036
1037 } withErrorBlock:^(BG1Error errorID) {
1038
1039 NSString *bg1Mac = @"";
1040 if (bg1IdpsDic[@"SerialNumber"] != nil) {
1041 bg1Mac = bg1IdpsDic[@"SerialNumber"];
1042 }
1043 NSString *descriptionStr = @"";
1044
1045 switch (errorID) {
1046 case BG1Error_LowBattery:
1047 descriptionStr=@"Battery is low.";
1048 break;
1049 case BG1Error_ResultOutOfMeasurementRage:
1050 descriptionStr=@"Glucose test result is out of the measurement range.";
1051 break;
1052 case BG1Error_UnvalidReferenceVoltage:
1053 descriptionStr=@"2.5V reference voltage error, not normal measurement, please repeat the test.";
1054 break;
1055 case BG1Error_StripUsed:
1056 descriptionStr=@"Strip is used or unknown moisture detected, discard the test strip and repeat the test with a new strip.";
1057 break;
1058 case BG1Error_CodeError:
1059 descriptionStr=@"CODE value check error. This error need let user scan code and call the send code function again,no alert need to show.";
1060 break;
1061 case BG1Error_RoomTemperatureOutOfRange1:
1062 case BG1Error_RoomTemperatureOutOfRange2:
1063 descriptionStr=@"The environmental temperature is beyond normal range, place the meter at room temperature for at least 30 minutes, then repeat the test.";
1064 break;
1065 case BG1Error_ResultLow:
1066 descriptionStr=@"Glucose test result is low.";
1067 break;
1068 case BG1Error_ResultHigh:
1069 descriptionStr=@"Glucose test result is high.";
1070 break;
1071 case BG1Error_DisConnented:
1072 descriptionStr=@"BG disConnented.";
1073 break;
1074 case BG1Error_SleepingMode:
1075 descriptionStr=@"BG sleeping mode.";
1076 break;
1077 case BG1Error_ParameterError:
1078 descriptionStr=@"Parameter input error.";
1079 break;
1080 default:
1081 descriptionStr=@"BG unknown.";
1082 break;
1083 }
1084
1085 NSDictionary* deviceInfo = @{@"mac":bg1Mac,@"action":@"action_measure_error_for_bg1",@"action_measure_error_for_bg1":[NSNumber numberWithInt:errorID],@"description":descriptionStr};
1086 [self sendEventWithName:@"event_notify_bg1" body:deviceInfo];
1087
1088 }];
1089
1090 } else if ([deviceType isEqualToString:kType_BG5]){
1091
1092 NSArray*bg5array = [[BG5Controller shareIHBg5Controller] getAllCurrentBG5Instace];
1093 if (bg5array.count) {
1094 for (int i=0; i<bg5array.count; i++) {
1095 BG5*mybg5=[bg5array objectAtIndex:i];
1096 NSDictionary* deviceInfo = [[NSDictionary alloc]init];
1097 deviceInfo = @{@"mac":mybg5.serialNumber,@"type":kType_BG5};
1098 [self sendEventWithName:kEvent_Device_Connected body:deviceInfo];
1099 }
1100
1101
1102 }
1103 } else if ([deviceType isEqualToString:kType_AM3S]){
1104
1105 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_AM3S andSerialNub:mac];
1106 }else if ([deviceType isEqualToString:kType_AM4]){
1107
1108 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_AM4 andSerialNub:mac];
1109
1110 }else if ([deviceType isEqualToString:kType_AM5]){
1111
1112 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_AM5 andSerialNub:mac];
1113
1114 }else if ([deviceType isEqualToString:kType_BP3L]){
1115
1116 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_BP3L andSerialNub:mac];
1117 }else if ([deviceType isEqualToString:kType_BP5S]){
1118
1119 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_BP5S andSerialNub:mac];
1120 }else if ([deviceType isEqualToString:kType_BP7S]){
1121
1122 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_BP7S andSerialNub:mac];
1123 }else if ([deviceType isEqualToString:kType_KN550]){
1124
1125 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_KN550BT andSerialNub:mac];
1126 }else if ([deviceType isEqualToString:kType_HS4]||[deviceType isEqualToString:kType_HS4S]){
1127
1128 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_HS4 andSerialNub:mac];
1129 }else if ([deviceType isEqualToString:kType_HS2]){
1130
1131 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_HS2 andSerialNub:mac];
1132 }else if ([deviceType isEqualToString:kType_PO3]){
1133
1134 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_PO3 andSerialNub:mac];
1135
1136 }else if ([deviceType isEqualToString:kType_BTM]){
1137
1138 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_THV3 andSerialNub:mac];
1139
1140 }else if ([deviceType isEqualToString:kType_ECG3]){
1141
1142 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_ECG3 andSerialNub:mac];
1143
1144 }else if ([deviceType isEqualToString:kType_ECG3USB]) {
1145
1146 ECG3USB*myecg3 = [[ECG3USBController shareECG3USBController] getCurrentECG3USBInstace];
1147 if (myecg3!=nil) {
1148
1149 NSDictionary* deviceInfo = @{@"mac":myecg3.serialNumber,@"type":kType_ECG3USB};
1150 [self sendEventWithName:kEvent_Device_Connected body:deviceInfo];
1151 }
1152 }else if ([deviceType isEqualToString:kType_BG5S]){
1153
1154 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_BG5S andSerialNub:mac];
1155
1156 }else if ([deviceType isEqualToString:kType_NT13B]){
1157
1158 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_NT13B andSerialNub:mac];
1159
1160 }else if ([deviceType isEqualToString:kType_TS28B]){
1161
1162 [self sendEventWithName:kEvent_Device_Connected body:@{@"mac":self.ts28b.serialNumber,@"type":@"TS28B"}];
1163
1164 }else if ([deviceType isEqualToString:kType_BG1S]){
1165
1166 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_BG1S andSerialNub:mac];
1167
1168 }else if ([deviceType isEqualToString:kType_HS2S]){
1169
1170 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_HS2S andSerialNub:mac];
1171 }else if ([deviceType isEqualToString:kType_PO1]){
1172
1173 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_PO1 andSerialNub:mac];
1174
1175 }else if ([deviceType isEqualToString:kType_PT3SBT]){
1176
1177 [[ConnectDeviceController commandGetInstance] commandContectDeviceWithDeviceType:HealthDeviceType_PO1 andSerialNub:mac];
1178
1179 }
1180
1181}
1182
1183
1184RCT_EXPORT_METHOD(getDevicesIDPS:(nonnull NSString *)mac callback:(RCTResponseSenderBlock)callback){
1185
1186
1187// {
1188// BTFirmwareVersion = "1.0.4";
1189// DeviceName = HS4S;
1190// FirmwareVersion = "1.0.2";
1191// HardwareVersion = "5.0.1";
1192// ID = "97FB0E73-7CE7-4B27-A7CE-EB76E9770002";
1193// Manufacture = iHealth;
1194// ModelNumber = "HS4S 11070";
1195// ProtocolString = "com.jiuan.BWSV01";
1196// SerialNumber = 8CDE529FD9DA;
1197// Type = 2;
1198// }
1199//
1200 // {"protocolstring":"com.jiuan.AMV12","accessoryname":"AM4","firmwareversion":"138","hardwareversion":"100","manufacture":"iHealth","serialnumber":"004D32079148","modenumber":"AM4 11070"}
1201
1202 NSArray*deviceArray=[[ManageDeviceController commandGetInstance] commandGetAllConnectDeviceArray];
1203
1204 if(deviceArray.count){
1205
1206 for (int i=0; i<deviceArray.count; i++) {
1207
1208 if ([mac isEqualToString:[[deviceArray objectAtIndex:i] valueForKey:@"SerialNumber"]]) {
1209
1210 NSDictionary*deviceDic=[deviceArray objectAtIndex:i];
1211
1212 NSMutableDictionary*dic=[[NSMutableDictionary alloc] init];
1213
1214 [dic setObject:[deviceDic objectForKey:@"ProtocolString"] forKey:@"protocolstring"];
1215
1216 [dic setObject:[deviceDic objectForKey:@"DeviceName"] forKey:@"accessoryname"];
1217
1218 if ([[deviceDic objectForKey:@"DeviceName"] isEqualToString:@"AM5"]) {
1219 [dic setObject:@"1.0.0" forKey:@"firmwareversion"];
1220
1221 [dic setObject:@"1.0.0" forKey:@"hardwareversion"];
1222
1223 [dic setObject:@"AM5" forKey:@"modenumber"];
1224 }else{
1225
1226 [dic setObject:[deviceDic objectForKey:@"FirmwareVersion"] forKey:@"firmwareversion"];
1227
1228 [dic setObject:[deviceDic objectForKey:@"HardwareVersion"] forKey:@"hardwareversion"];
1229
1230 [dic setObject:[deviceDic objectForKey:@"ModelNumber"] forKey:@"modenumber"];
1231 }
1232
1233
1234
1235
1236
1237 if(![[deviceDic objectForKey:@"DeviceName"] isEqualToString:@"BP5"] && ![[deviceDic objectForKey:@"DeviceName"] isEqualToString:@"BP7"]&& ![[deviceDic objectForKey:@"DeviceName"] isEqualToString:@"AM5"]){
1238
1239 [dic setObject:[deviceDic objectForKey:@"Manufacture"] forKey:@"manufacture"];
1240 }
1241
1242
1243 [dic setObject:[deviceDic objectForKey:@"SerialNumber"] forKey:@"serialNumber"];
1244
1245
1246
1247
1248 callback(@[dic]);
1249
1250 }
1251
1252 }
1253
1254 }else{
1255
1256
1257
1258 }
1259
1260
1261
1262}
1263
1264RCT_EXPORT_METHOD(authenConfigureInfo:(NSString *)userID clientID:(NSString *)clientID clientSecret:(NSString *)clientSecret){
1265
1266 HealthUser *currentUser = [[HealthUser alloc]init];
1267 currentUser.userAccount = userID;
1268 currentUser.clientID = clientID;
1269 currentUser.clientSecret = clientSecret;
1270
1271 [[IHSDKCloudUser commandGetSDKUserInstance]commandSDKUserValidation:currentUser UserDeviceAccess:^(NSArray *DeviceAccessArray) {
1272
1273 } UserValidationSuccess:^(UserAuthenResult result) {
1274 [self authenResult:result userID:userID clientID:clientID clientSecret:clientSecret];
1275
1276 } UserValidationReturn:^(NSString *userID) {
1277
1278 } DisposeErrorBlock:^(UserAuthenResult errorID) {
1279 if (errorID == UserAuthen_UserInvalidateRight) {
1280 [self authenResult:UserAuthen_LoginSuccess userID:userID clientID:clientID clientSecret:clientSecret];
1281 }else{
1282 [self authenResult:errorID userID:userID clientID:clientID clientSecret:clientSecret];
1283 }
1284
1285 }];
1286
1287}
1288
1289- (void)authenResult:(UserAuthenResult)result userID:(NSString*)userID clientID:(NSString*)clientID clientSecret:(NSString*)clientSecret{
1290 if (result <= UserAuthen_TrySuccess) {
1291 NSArray* userInfo = @[userID,clientID,clientSecret];
1292 [[NSUserDefaults standardUserDefaults] setObject:userInfo forKey:FetchUserInfo];
1293 }else{
1294 [[NSUserDefaults standardUserDefaults] removeObjectForKey:FetchUserInfo];
1295 }
1296 [self sendEventWithName:kEvent_Authenticate_Result body:@{@"authen":@(result)}];
1297}
1298
1299RCT_EXPORT_METHOD(authenAppSecret:(NSString *)appSecret){
1300
1301
1302 [[IHSDKCloudUser commandGetSDKUserInstance] commandSDKUserValidationWithAppSecret:appSecret UserValidationSuccess:^(UserAuthenResult result) {
1303
1304 [self sendEventWithName:kEvent_Authenticate_Result body:@{@"authen":@(result)}];
1305
1306 } DisposeErrorBlock:^(UserAuthenResult errorID) {
1307
1308 }];
1309
1310}
1311
1312RCT_EXPORT_METHOD(disconnectDevice:(NSString*)mac type:(NSString*)type){
1313 NSLog(@"API disconnectDevice is not avaliable in iOS platform, please the specific device's disconnect API.");
1314}
1315
1316+ (NSArray*)userInfos{
1317 NSArray* userInfos = [[NSUserDefaults standardUserDefaults] objectForKey:FetchUserInfo];
1318 if (userInfos.count == 3) {
1319 return userInfos;
1320 }else{
1321 return nil;
1322 }
1323}
1324
1325+ (NSString*)autherizedUserID{
1326 return [[self userInfos] objectAtIndex:0];
1327}
1328
1329+ (NSString*)autherizedClientID{
1330 return [[self userInfos] objectAtIndex:1];
1331}
1332
1333+ (NSString*)autherizedClientSecret{
1334 return [[self userInfos] objectAtIndex:2];
1335}
1336
1337
1338@end