diff options
| author | hc <haocheng.xie@respiree.com> | 2026-04-13 15:17:52 +0800 |
|---|---|---|
| committer | hc <haocheng.xie@respiree.com> | 2026-04-13 15:17:52 +0800 |
| commit | d6d9a09d505d11148599a95a5be3e1351edbe0ac (patch) | |
| tree | a5f5891983d1ff207e99f683a5e151519cef4980 /libs/ihealth-sdk/ios/ReactNativeIOSLibrary/AM3SModule.m | |
| parent | e4fb9966e762852bf17f21c8406501d42fae0b61 (diff) | |
Local iHealth SDK, device detail screen, iOS event fixes
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/AM3SModule.m')
| -rw-r--r-- | libs/ihealth-sdk/ios/ReactNativeIOSLibrary/AM3SModule.m | 788 |
1 files changed, 788 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/AM3SModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/AM3SModule.m new file mode 100644 index 0000000..f6fcff4 --- /dev/null +++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/AM3SModule.m | |||
| @@ -0,0 +1,788 @@ | |||
| 1 | // | ||
| 2 | // AM3SModule.m | ||
| 3 | // ReactNativeIOSLibrary | ||
| 4 | // | ||
| 5 | // Created by daiqingquan on 2016/11/23. | ||
| 6 | // Copyright © 2016年 daiqingquan. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "AM3SModule.h" | ||
| 10 | #import "AMProfileModule.h" | ||
| 11 | #import "AMMacroFile.h" | ||
| 12 | #import "AM3SController_V2.h" | ||
| 13 | #import "AM3S_V2.h" | ||
| 14 | |||
| 15 | #define EVENT_NOTIFY @"event_notify_am3s" | ||
| 16 | |||
| 17 | @implementation AM3SModule | ||
| 18 | |||
| 19 | RCT_EXPORT_MODULE() | ||
| 20 | - (NSArray<NSString *> *)supportedEvents { | ||
| 21 | return @[@"event_notify", @"event_scan_device", @"event_scan_finish", | ||
| 22 | @"event_device_connected", @"event_device_connect_failed", | ||
| 23 | @"event_device_disconnect", @"event_authenticate_result", | ||
| 24 | @"event_notify_ts28b", @"event_notify_bg1", | ||
| 25 | @"action_connect_result_for_bg1"]; | ||
| 26 | } | ||
| 27 | |||
| 28 | - (NSDictionary *)constantsToExport | ||
| 29 | { | ||
| 30 | return @{ | ||
| 31 | @"Event_Notify": EVENT_NOTIFY | ||
| 32 | |||
| 33 | }; | ||
| 34 | } | ||
| 35 | + (BOOL)requiresMainQueueSetup | ||
| 36 | { | ||
| 37 | return YES; | ||
| 38 | } | ||
| 39 | #pragma mark | ||
| 40 | #pragma mark - Init | ||
| 41 | -(id)init | ||
| 42 | { | ||
| 43 | if (self=[super init]) | ||
| 44 | { | ||
| 45 | |||
| 46 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(DeviceConnectForAM3S:) name:AM3SConnectNoti object:nil]; | ||
| 47 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(DeviceDisConnectForAM3S:) name:AM3SDisConnectNoti object:nil]; | ||
| 48 | |||
| 49 | [AM3SController_V2 shareIHAM3SController]; | ||
| 50 | |||
| 51 | } | ||
| 52 | return self; | ||
| 53 | } | ||
| 54 | |||
| 55 | -(AM3S_V2*)getAM3SWithMac:(NSString*)mac{ | ||
| 56 | |||
| 57 | AM3SController_V2 *controller = [AM3SController_V2 shareIHAM3SController]; | ||
| 58 | NSArray *amDeviceArray = [controller getAllCurrentAM3SInstace]; | ||
| 59 | |||
| 60 | for(AM3S_V2 *tempAM3S in amDeviceArray){ | ||
| 61 | if([mac isEqualToString:tempAM3S.serialNumber]){ | ||
| 62 | |||
| 63 | return tempAM3S; | ||
| 64 | break; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | return nil; | ||
| 69 | } | ||
| 70 | |||
| 71 | #pragma mark | ||
| 72 | #pragma mark - Notification | ||
| 73 | #pragma mark - AM3S | ||
| 74 | |||
| 75 | -(void)DeviceConnectForAM3S:(NSNotification *)tempNoti{ | ||
| 76 | AM3SController_V2 *controller = [AM3SController_V2 shareIHAM3SController]; | ||
| 77 | NSArray *amDeviceArray = [controller getAllCurrentAM3SInstace]; | ||
| 78 | |||
| 79 | AM3S_V2 *AMInstance = [amDeviceArray objectAtIndex:0]; | ||
| 80 | } | ||
| 81 | |||
| 82 | -(void)DeviceDisConnectForAM3S:(NSNotification *)tempNoti{ | ||
| 83 | AM3SController_V2 *controller = [AM3SController_V2 shareIHAM3SController]; | ||
| 84 | |||
| 85 | |||
| 86 | } | ||
| 87 | #pragma mark - Method | ||
| 88 | |||
| 89 | |||
| 90 | #pragma mark-获取连接设备 | ||
| 91 | RCT_EXPORT_METHOD(getAllConnectedDevices){ | ||
| 92 | |||
| 93 | |||
| 94 | NSArray*am3sarray= [[AM3SController_V2 shareIHAM3SController] getAllCurrentAM3SInstace]; | ||
| 95 | |||
| 96 | NSMutableArray*deviceMacArray=[NSMutableArray array]; | ||
| 97 | |||
| 98 | for (int i=0; i<[am3sarray count]; i++) { | ||
| 99 | |||
| 100 | AM3S_V2*am3s=[am3sarray objectAtIndex:i]; | ||
| 101 | |||
| 102 | [deviceMacArray addObject:am3s.serialNumber]; | ||
| 103 | |||
| 104 | } | ||
| 105 | |||
| 106 | NSDictionary* deviceInfo = @{@"action":@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray}; | ||
| 107 | |||
| 108 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 109 | |||
| 110 | |||
| 111 | } | ||
| 112 | |||
| 113 | |||
| 114 | #pragma mark-恢复出厂 | ||
| 115 | RCT_EXPORT_METHOD(reset:(nonnull NSString *)mac){ | ||
| 116 | |||
| 117 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 118 | |||
| 119 | [[self getAM3SWithMac:mac] commandAM3SResetDevice:^(BOOL resetSuc) { | ||
| 120 | |||
| 121 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"reset_am",@"reset":[NSNumber numberWithInteger:resetSuc]}; | ||
| 122 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 123 | |||
| 124 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 125 | |||
| 126 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 127 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 128 | }]; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | #pragma mark - 得到用户ID | ||
| 132 | RCT_EXPORT_METHOD(getUserId:(nonnull NSString *)mac){ | ||
| 133 | |||
| 134 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 135 | |||
| 136 | [[self getAM3SWithMac:mac] commandAM3SGetDeviceUserID:^(unsigned int userID) { | ||
| 137 | |||
| 138 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"userid_am",@"userid":[NSNumber numberWithInteger:userID]}; | ||
| 139 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 140 | |||
| 141 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 142 | |||
| 143 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 144 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 145 | }]; | ||
| 146 | |||
| 147 | } | ||
| 148 | } | ||
| 149 | #pragma mark - 设置用户ID | ||
| 150 | RCT_EXPORT_METHOD(setUserId:(nonnull NSString *)mac :(nonnull NSNumber *)uesrID){ | ||
| 151 | |||
| 152 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 153 | |||
| 154 | [[self getAM3SWithMac:mac] commandAM3SSetUserID:uesrID withFinishResult:^(BOOL resetSuc) { | ||
| 155 | |||
| 156 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_userid_success_am"}; | ||
| 157 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 158 | |||
| 159 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 160 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 161 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 162 | }]; | ||
| 163 | } | ||
| 164 | } | ||
| 165 | #pragma mark - 同步时间 | ||
| 166 | RCT_EXPORT_METHOD(syncRealTime:(nonnull NSString *)mac){ | ||
| 167 | |||
| 168 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 169 | |||
| 170 | [[self getAM3SWithMac:mac] commandAM3SSyncTime:^(BOOL resetSuc) { | ||
| 171 | |||
| 172 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_sync_time_success_am"}; | ||
| 173 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 174 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 175 | |||
| 176 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 177 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 178 | }]; | ||
| 179 | } | ||
| 180 | } | ||
| 181 | #pragma mark - 设置用户信息 | ||
| 182 | RCT_EXPORT_METHOD(setUserInfo:(nonnull NSString *)mac :(nonnull NSNumber *)age :(nonnull NSNumber *)height :(nonnull NSNumber *)weight :(nonnull NSNumber *)gender :(nonnull NSNumber *)unit :(nonnull NSNumber *)target :(nonnull NSNumber *)activityLevel){ | ||
| 183 | |||
| 184 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 185 | |||
| 186 | HealthUser *myUser = [[HealthUser alloc]init]; | ||
| 187 | myUser.age = age; | ||
| 188 | myUser.sex = UserSex_Male; | ||
| 189 | myUser.height = height; | ||
| 190 | myUser.weight = weight; | ||
| 191 | myUser.activityLevel = activityLevel; | ||
| 192 | |||
| 193 | NSDictionary *dic = [[NSMutableDictionary alloc]init]; | ||
| 194 | [[self getAM3SWithMac:mac] commandAM3SSetUserInfo:myUser withUnit:unit withActiveGoal:target withSetUserInfoFinishResult:^(BOOL resetSuc) { | ||
| 195 | |||
| 196 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_userinfo_success_am"}; | ||
| 197 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 198 | |||
| 199 | } withSetBMR:^(BOOL resetSuc) { | ||
| 200 | |||
| 201 | |||
| 202 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 203 | |||
| 204 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 205 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 206 | }]; | ||
| 207 | } | ||
| 208 | } | ||
| 209 | #pragma mark - 得到用户信息 | ||
| 210 | RCT_EXPORT_METHOD(getUserInfo:(nonnull NSString *)mac){ | ||
| 211 | |||
| 212 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 213 | |||
| 214 | [[self getAM3SWithMac:mac] commandAM3SGetUserInfo:^(NSDictionary *userInfo) { | ||
| 215 | |||
| 216 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_userinfo_am",@"age":[userInfo valueForKey:@"Age"],@"step":[userInfo valueForKey:@"Step"],@"height":[userInfo valueForKey:@"Height"],@"gender":[userInfo valueForKey:@"Gender"],@"weight":[userInfo valueForKey:@"Weight"],@"unit":[userInfo valueForKey:@"Unit"],@"target1":[userInfo valueForKey:@"TotalStep1"],@"target2":[userInfo valueForKey:@"TotalStep2"],@"target3":[userInfo valueForKey:@"TotalStep3"]}; | ||
| 217 | |||
| 218 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 219 | |||
| 220 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 221 | |||
| 222 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 223 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 224 | }]; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | #pragma mark - 得到闹钟个数 | ||
| 228 | RCT_EXPORT_METHOD(getAlarmClockNum:(nonnull NSString *)mac){ | ||
| 229 | |||
| 230 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 231 | |||
| 232 | [[self getAM3SWithMac:mac] commandAM3SGetTotoalAlarmInfo:^(NSMutableArray *totoalAlarmArray) { | ||
| 233 | |||
| 234 | NSMutableArray * IDArray = [[NSMutableArray alloc]init]; | ||
| 235 | |||
| 236 | if (totoalAlarmArray.count > 0){ | ||
| 237 | |||
| 238 | for (NSDictionary *dic in totoalAlarmArray) { | ||
| 239 | [IDArray addObject:[dic valueForKey:@"AlarmId"]]; | ||
| 240 | } | ||
| 241 | } | ||
| 242 | |||
| 243 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_alarmnum_am",@"alarmclocknumber":[NSNumber numberWithInt:IDArray.count],@"alarmclocknumberid":IDArray}; | ||
| 244 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 245 | |||
| 246 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 247 | |||
| 248 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 249 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 250 | }]; | ||
| 251 | } | ||
| 252 | } | ||
| 253 | #pragma mark - 得到闹钟信息 | ||
| 254 | RCT_EXPORT_METHOD(getAlarmClockDetail:(nonnull NSString *)mac :(nonnull NSArray *)alarmIDS){ | ||
| 255 | |||
| 256 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 257 | |||
| 258 | [[self getAM3SWithMac:mac] commandAM3SGetTotoalAlarmInfo:^(NSMutableArray *totoalAlarmArray) { | ||
| 259 | |||
| 260 | NSMutableArray * alarmInfoArray = [[NSMutableArray alloc]init]; | ||
| 261 | |||
| 262 | if (totoalAlarmArray.count > 0){ | ||
| 263 | |||
| 264 | for (NSDictionary *dic in totoalAlarmArray) { | ||
| 265 | |||
| 266 | |||
| 267 | NSMutableDictionary *alartDic = [[NSMutableDictionary alloc]init]; | ||
| 268 | |||
| 269 | for (NSNumber * alarmID in alarmIDS) { | ||
| 270 | |||
| 271 | NSNumber *deviceAlarmID = [dic valueForKey:@"AlarmId"]; | ||
| 272 | |||
| 273 | if(deviceAlarmID.intValue == alarmID.intValue){ | ||
| 274 | |||
| 275 | [alartDic setValue:[dic valueForKey:@"AlarmId"] forKey:@"alarmid"]; | ||
| 276 | |||
| 277 | NSDate *date = [dic valueForKey:@"Time"]; | ||
| 278 | NSDateFormatter *dateFormater=[[NSDateFormatter alloc]init]; | ||
| 279 | [dateFormater setTimeZone:[NSTimeZone defaultTimeZone]]; | ||
| 280 | [dateFormater setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; | ||
| 281 | [dateFormater setDateFormat:@"HH:mm"]; | ||
| 282 | NSString *dateString = [dateFormater stringFromDate:date]; | ||
| 283 | |||
| 284 | [alartDic setValue:dateString forKey:@"time"]; | ||
| 285 | [alartDic setValue:[dic valueForKey:@"IsRepeat"] forKey:@"repeat"]; | ||
| 286 | |||
| 287 | NSMutableDictionary * weekDic = [[NSMutableDictionary alloc]init]; | ||
| 288 | [weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:0] forKey:@"sun"]; | ||
| 289 | [weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:1] forKey:@"mon"]; | ||
| 290 | [weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:2] forKey:@"tue"]; | ||
| 291 | [weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:3] forKey:@"wed"]; | ||
| 292 | [weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:4] forKey:@"thu"]; | ||
| 293 | [weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:5] forKey:@"fri"]; | ||
| 294 | [weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:6] forKey:@"sat"]; | ||
| 295 | |||
| 296 | [alartDic setValue:weekDic forKey:@"get_alarm_week"]; | ||
| 297 | [alartDic setValue:[dic valueForKey:@"Switch"] forKey:@"switch"]; | ||
| 298 | [alarmInfoArray addObject:alartDic]; | ||
| 299 | |||
| 300 | } | ||
| 301 | } | ||
| 302 | } | ||
| 303 | |||
| 304 | } | ||
| 305 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_alarminfo_am",@"alarmclockdetail":alarmInfoArray}; | ||
| 306 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 307 | |||
| 308 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 309 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 310 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 311 | }]; | ||
| 312 | } | ||
| 313 | } | ||
| 314 | #pragma mark - 设置闹钟信息 | ||
| 315 | RCT_EXPORT_METHOD(setAlarmClock:(nonnull NSString *)mac :(nonnull NSNumber *)alarmID :(nonnull NSNumber *)hour :(nonnull NSNumber *)min :(nonnull NSNumber*)isRepeat :(nonnull NSArray *)weekArray :(nonnull NSNumber *)isOn){ | ||
| 316 | |||
| 317 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 318 | |||
| 319 | if(alarmID.integerValue < 0 || alarmID.integerValue > 3 || | ||
| 320 | hour.integerValue > 23 || hour.integerValue < 0 || | ||
| 321 | min.integerValue > 59 || min.integerValue < 0){ | ||
| 322 | |||
| 323 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:400]}; | ||
| 324 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 325 | return; | ||
| 326 | } | ||
| 327 | |||
| 328 | NSDateFormatter *formater=[[NSDateFormatter alloc]init]; | ||
| 329 | [formater setTimeZone:[NSTimeZone defaultTimeZone]]; | ||
| 330 | [formater setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; | ||
| 331 | [formater setDateFormat:@"HH-mm"]; | ||
| 332 | NSString * timeStr = [NSString stringWithFormat:@"%@-%@",hour,min]; | ||
| 333 | NSDate *date = [formater dateFromString:timeStr]; | ||
| 334 | |||
| 335 | |||
| 336 | NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:alarmID,@"AlarmId",date,@"Time",isRepeat,@"IsRepeat",weekArray,@"Week",isOn,@"Switch", nil]; | ||
| 337 | |||
| 338 | |||
| 339 | [[self getAM3SWithMac:mac] commandAM3SSetAlarmDictionary:dic withFinishResult:^(BOOL resetSuc) { | ||
| 340 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_alarminfo_success_am"}; | ||
| 341 | |||
| 342 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 343 | |||
| 344 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 345 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 346 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 347 | }]; | ||
| 348 | } | ||
| 349 | } | ||
| 350 | #pragma mark - 删除闹钟信息 | ||
| 351 | RCT_EXPORT_METHOD(deleteAlarmClock:(nonnull NSString *)mac :(nonnull NSNumber *)alarmID){ | ||
| 352 | |||
| 353 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 354 | |||
| 355 | [[self getAM3SWithMac:mac] commandAM3SDeleteAlarmID:alarmID withFinishResult:^(BOOL resetSuc) { | ||
| 356 | |||
| 357 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"delete_alarm_success_am"}; | ||
| 358 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 359 | |||
| 360 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 361 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 362 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 363 | }]; | ||
| 364 | } | ||
| 365 | } | ||
| 366 | #pragma mark - 查询提醒信息 | ||
| 367 | RCT_EXPORT_METHOD(getActivityRemind:(nonnull NSString *)mac){ | ||
| 368 | |||
| 369 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 370 | |||
| 371 | [[self getAM3SWithMac:mac] commandAM3SGetReminderInfo:^(NSArray *remindInfo) { | ||
| 372 | |||
| 373 | NSDictionary *dic = [remindInfo objectAtIndex:0]; | ||
| 374 | |||
| 375 | NSDate *date = [dic valueForKey:@"Time"]; | ||
| 376 | NSDateFormatter *dateFormater=[[NSDateFormatter alloc]init]; | ||
| 377 | [dateFormater setTimeZone:[NSTimeZone defaultTimeZone]]; | ||
| 378 | [dateFormater setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; | ||
| 379 | [dateFormater setDateFormat:@"HH:mm"]; | ||
| 380 | NSString *dateString = [dateFormater stringFromDate:date]; | ||
| 381 | |||
| 382 | |||
| 383 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_activity_remind_am",@"time":dateString,@"switch":[dic valueForKey:@"Switch"]}; | ||
| 384 | |||
| 385 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 386 | |||
| 387 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 388 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 389 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 390 | }]; | ||
| 391 | } | ||
| 392 | } | ||
| 393 | #pragma mark - 设置提醒信息 | ||
| 394 | RCT_EXPORT_METHOD(setActivityRemind:(nonnull NSString *)mac :(nonnull NSNumber *)hour :(nonnull NSNumber *)min :(nonnull NSNumber *)isOn){ | ||
| 395 | |||
| 396 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 397 | |||
| 398 | if(hour.integerValue > 23 || hour.integerValue < 0 || | ||
| 399 | min.integerValue > 59 || min.integerValue < 0){ | ||
| 400 | |||
| 401 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:400]}; | ||
| 402 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 403 | return; | ||
| 404 | } | ||
| 405 | |||
| 406 | NSDateFormatter *formater=[[NSDateFormatter alloc]init]; | ||
| 407 | [formater setTimeZone:[NSTimeZone defaultTimeZone]]; | ||
| 408 | [formater setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; | ||
| 409 | [formater setDateFormat:@"HH-mm"]; | ||
| 410 | NSString * timeStr = [NSString stringWithFormat:@"%@-%@",hour,min]; | ||
| 411 | NSDate *date = [formater dateFromString:timeStr]; | ||
| 412 | |||
| 413 | |||
| 414 | NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:date,@"Time",isOn,@"Switch", nil]; | ||
| 415 | |||
| 416 | [[self getAM3SWithMac:mac] commandAM3SSetReminderDictionary:dic withFinishResult:^(BOOL resetSuc) { | ||
| 417 | |||
| 418 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_activityremind_success_am"}; | ||
| 419 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 420 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 421 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 422 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 423 | }]; | ||
| 424 | } | ||
| 425 | } | ||
| 426 | #pragma mark - 同步运动 | ||
| 427 | RCT_EXPORT_METHOD(syncActivityData:(nonnull NSString *)mac){ | ||
| 428 | |||
| 429 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 430 | |||
| 431 | [[self getAM3SWithMac:mac] commandAM3SStartSyncActiveData:^(NSDictionary *startDataDictionary) { | ||
| 432 | |||
| 433 | |||
| 434 | |||
| 435 | } withActiveHistoryData:^(NSArray *historyDataArray) { | ||
| 436 | |||
| 437 | NSMutableArray *lastArray = [[NSMutableArray alloc]init]; | ||
| 438 | for (NSDictionary *dic in historyDataArray) { | ||
| 439 | |||
| 440 | NSMutableDictionary * lastDic = [[NSMutableDictionary alloc]init]; | ||
| 441 | |||
| 442 | |||
| 443 | NSDateFormatter *dateFormat = nil; | ||
| 444 | |||
| 445 | if (dateFormat == nil) { | ||
| 446 | dateFormat = [[NSDateFormatter alloc] init]; | ||
| 447 | [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式 | ||
| 448 | } | ||
| 449 | |||
| 450 | NSString *locationString=[dateFormat stringFromDate:[dic valueForKey:AMDate]]; | ||
| 451 | |||
| 452 | [lastDic setValue:locationString forKey:@"time"]; | ||
| 453 | |||
| 454 | [lastDic setValue:[dic valueForKey:AMStepSize] forKey:@"stepsize"]; | ||
| 455 | [lastDic setValue:[dic valueForKey:AMCalorie] forKey:@"calorie"]; | ||
| 456 | [lastDic setValue:[dic valueForKey:AMStepNum] forKey:@"step"]; | ||
| 457 | [lastDic setValue:[dic valueForKey:@"dataID"] forKey:@"dataID"]; | ||
| 458 | [lastArray addObject:lastDic]; | ||
| 459 | } | ||
| 460 | |||
| 461 | NSDictionary *dictionary = [NSDictionary dictionaryWithObject:lastArray forKey:@"activity_each_data"]; | ||
| 462 | NSArray *array = [NSArray arrayWithObjects:dictionary, nil]; | ||
| 463 | |||
| 464 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"sync_activity_data_am",@"activity":array}; | ||
| 465 | |||
| 466 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 467 | |||
| 468 | } withActiveFinishTransmission:^{ | ||
| 469 | |||
| 470 | |||
| 471 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 472 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 473 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 474 | }]; | ||
| 475 | } | ||
| 476 | } | ||
| 477 | #pragma mark - 同步睡眠 | ||
| 478 | RCT_EXPORT_METHOD(syncSleepData:(nonnull NSString *)mac){ | ||
| 479 | |||
| 480 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 481 | |||
| 482 | [[self getAM3SWithMac:mac] commandAM3SStartSyncSleepData:^(NSDictionary *startDataDictionary) { | ||
| 483 | |||
| 484 | |||
| 485 | } withSleepHistoryData:^(NSArray *historyDataArray) { | ||
| 486 | |||
| 487 | NSMutableArray *lastArray = [[NSMutableArray alloc]init]; | ||
| 488 | |||
| 489 | |||
| 490 | for (NSArray *array in historyDataArray) { | ||
| 491 | |||
| 492 | for (NSDictionary *dic in array) { | ||
| 493 | |||
| 494 | NSMutableDictionary * lastDic = [[NSMutableDictionary alloc]init]; | ||
| 495 | NSDateFormatter *dateFormat = nil; | ||
| 496 | |||
| 497 | if (dateFormat == nil) { | ||
| 498 | dateFormat = [[NSDateFormatter alloc] init]; | ||
| 499 | [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式 | ||
| 500 | } | ||
| 501 | |||
| 502 | NSString *locationString=[dateFormat stringFromDate:[dic valueForKey:AMDate]]; | ||
| 503 | |||
| 504 | [lastDic setValue:locationString forKey:@"time"]; [lastDic setValue:[dic valueForKey:@"SleepData"] forKey:@"level"]; | ||
| 505 | [lastDic setValue:[dic valueForKey:@"dataID"] forKey:@"dataID"]; | ||
| 506 | [lastArray addObject:lastDic]; | ||
| 507 | |||
| 508 | } | ||
| 509 | } | ||
| 510 | |||
| 511 | NSDictionary *dictionary = [NSDictionary dictionaryWithObject:lastArray forKey:@"sleep_each_data"]; | ||
| 512 | NSArray *array = [NSArray arrayWithObjects:dictionary, nil]; | ||
| 513 | |||
| 514 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"sync_sleep_data_am",@"sleep":array}; | ||
| 515 | |||
| 516 | |||
| 517 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 518 | |||
| 519 | |||
| 520 | } withSleepFinishTransmission:^{ | ||
| 521 | |||
| 522 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 523 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 524 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 525 | }]; | ||
| 526 | } | ||
| 527 | } | ||
| 528 | #pragma mark - 同步阶段性 | ||
| 529 | RCT_EXPORT_METHOD(syncStageReportData:(nonnull NSString *)mac){ | ||
| 530 | |||
| 531 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 532 | |||
| 533 | [[self getAM3SWithMac:mac] commandAM3SStartSyncStageData:^(NSArray *measureDataArray) { | ||
| 534 | |||
| 535 | NSMutableArray *lastArray = [[NSMutableArray alloc]init]; | ||
| 536 | |||
| 537 | |||
| 538 | NSPredicate *pre = [NSPredicate predicateWithFormat:@"ReportState == 1"]; | ||
| 539 | NSArray *workoutArray = [measureDataArray filteredArrayUsingPredicate:pre]; | ||
| 540 | if (workoutArray.count != 0) | ||
| 541 | { | ||
| 542 | for (NSDictionary *dic in workoutArray) { | ||
| 543 | |||
| 544 | NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init]; | ||
| 545 | [dictionary setValue:@"stage_data_type_workout" forKey:@"type"]; | ||
| 546 | |||
| 547 | NSDateFormatter *dateFormat = nil; | ||
| 548 | |||
| 549 | if (dateFormat == nil) { | ||
| 550 | dateFormat = [[NSDateFormatter alloc] init]; | ||
| 551 | [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式 | ||
| 552 | } | ||
| 553 | |||
| 554 | NSString *locationString=[dateFormat stringFromDate:[dic valueForKey:Work_outMeasureDate]]; | ||
| 555 | |||
| 556 | |||
| 557 | |||
| 558 | [dictionary setValue:locationString forKey:@"stoptime"]; | ||
| 559 | [dictionary setValue:[dic valueForKey:Work_outTimeNumber] forKey:@"usedtime"]; | ||
| 560 | [dictionary setValue:[dic valueForKey:Work_outStepNumber] forKey:@"stage_data_workout_step"]; | ||
| 561 | [dictionary setValue:[dic valueForKey:Work_outLengthNumber] forKey:@"stage_data_distance"]; | ||
| 562 | [dictionary setValue:[dic valueForKey:Work_outCalories] forKey:@"calorie"]; | ||
| 563 | [dictionary setValue:[dic valueForKey:@"dataID"] forKey:@"dataID"]; | ||
| 564 | [lastArray addObject:dictionary]; | ||
| 565 | } | ||
| 566 | } | ||
| 567 | |||
| 568 | NSPredicate *predicateSleep = [NSPredicate predicateWithFormat:@"ReportState == 2"]; | ||
| 569 | NSArray *sleepArray = [measureDataArray filteredArrayUsingPredicate:predicateSleep]; | ||
| 570 | if (sleepArray.count != 0) | ||
| 571 | { | ||
| 572 | for (NSDictionary *dic in sleepArray) { | ||
| 573 | |||
| 574 | |||
| 575 | |||
| 576 | |||
| 577 | NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init]; | ||
| 578 | [dictionary setValue:@"sleep" forKey:@"type"]; | ||
| 579 | |||
| 580 | |||
| 581 | NSDateFormatter *dateFormat = nil; | ||
| 582 | |||
| 583 | if (dateFormat == nil) { | ||
| 584 | dateFormat = [[NSDateFormatter alloc] init]; | ||
| 585 | [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式 | ||
| 586 | } | ||
| 587 | |||
| 588 | NSString *locationString=[dateFormat stringFromDate:[dic valueForKey:Sleep_summaryMeasureDate]]; | ||
| 589 | |||
| 590 | |||
| 591 | [dictionary setValue:locationString forKey:@"stoptime"]; | ||
| 592 | [dictionary setValue:[dic valueForKey:Sleep_summarySleepTime] forKey:@"usedtime"]; | ||
| 593 | [dictionary setValue:[dic valueForKey:Sleep_summarysleepEfficiency] forKey:@"sleepefficiency"]; | ||
| 594 | [dictionary setValue:[dic valueForKey:Sleep_summarysleepAddMinute] forKey:@"is50min"]; | ||
| 595 | [lastArray addObject:dictionary]; | ||
| 596 | } | ||
| 597 | |||
| 598 | } | ||
| 599 | |||
| 600 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"sync_stage_data_am",@"stage_data":lastArray}; | ||
| 601 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 602 | |||
| 603 | |||
| 604 | } withStageDataFinishTransmission:^(BOOL resetSuc) { | ||
| 605 | |||
| 606 | |||
| 607 | |||
| 608 | |||
| 609 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 610 | |||
| 611 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 612 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 613 | }]; | ||
| 614 | } | ||
| 615 | } | ||
| 616 | #pragma mark - 同步阶实时数据 | ||
| 617 | RCT_EXPORT_METHOD(syncRealData:(nonnull NSString *)mac){ | ||
| 618 | |||
| 619 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 620 | |||
| 621 | [[self getAM3SWithMac:mac] commandAM3SStartSyncCurrentActiveData:^(NSDictionary *activeDictionary) { | ||
| 622 | |||
| 623 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"sync_real_data_am",@"step":[activeDictionary valueForKey:@"Step"],@"calorie":[activeDictionary valueForKey:@"Calories"],@"totalcalories":[activeDictionary valueForKey:@"TotalCalories"]}; | ||
| 624 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 625 | |||
| 626 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 627 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 628 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 629 | }]; | ||
| 630 | } | ||
| 631 | } | ||
| 632 | #pragma mark - 查询状态 | ||
| 633 | RCT_EXPORT_METHOD(queryAMState:(nonnull NSString *)mac){ | ||
| 634 | |||
| 635 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 636 | |||
| 637 | __block NSInteger index; | ||
| 638 | |||
| 639 | [[self getAM3SWithMac:mac] commandAM3SGetDeviceStateInfo:^(AM3SQueryState queryState) { | ||
| 640 | |||
| 641 | index = queryState; | ||
| 642 | |||
| 643 | } withBattery:^(NSNumber *battery) { | ||
| 644 | |||
| 645 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"query_state_am",@"query_state":[NSNumber numberWithInteger:index],@"battery":battery}; | ||
| 646 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 647 | |||
| 648 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 649 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 650 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 651 | }]; | ||
| 652 | } | ||
| 653 | } | ||
| 654 | #pragma mark - 设置BMR | ||
| 655 | RCT_EXPORT_METHOD(setUserBmr:(nonnull NSString *)mac :(nonnull NSNumber *)bmr){ | ||
| 656 | |||
| 657 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 658 | |||
| 659 | [[self getAM3SWithMac:mac] commandAM3SSetBMR:bmr withFinishResult:^(BOOL resetSuc) { | ||
| 660 | |||
| 661 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_bmr_success_am"}; | ||
| 662 | |||
| 663 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 664 | |||
| 665 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 666 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 667 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 668 | }]; | ||
| 669 | } | ||
| 670 | } | ||
| 671 | #pragma mark - 随机数 | ||
| 672 | RCT_EXPORT_METHOD(sendRandom:(nonnull NSString *)mac){ | ||
| 673 | |||
| 674 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 675 | |||
| 676 | [[self getAM3SWithMac:mac] commandAM3SSetRandomNumber:^(NSString *randomNumString) { | ||
| 677 | |||
| 678 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_random_am",@"random":randomNumString}; | ||
| 679 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 680 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 681 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 682 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 683 | }]; | ||
| 684 | } | ||
| 685 | } | ||
| 686 | #pragma mark - 断开 | ||
| 687 | RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){ | ||
| 688 | |||
| 689 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 690 | |||
| 691 | [[self getAM3SWithMac:mac] commandAM3SDisconnect:^(BOOL resetSuc) { | ||
| 692 | |||
| 693 | NSDictionary* deviceInfo = @{@"mac":mac}; | ||
| 694 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 695 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 696 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 697 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 698 | }]; | ||
| 699 | } | ||
| 700 | } | ||
| 701 | |||
| 702 | |||
| 703 | |||
| 704 | |||
| 705 | #pragma mark-设置小时制 | ||
| 706 | RCT_EXPORT_METHOD(setHourMode:(nonnull NSString *)mac :(nonnull NSNumber*)hourMode){ | ||
| 707 | |||
| 708 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 709 | |||
| 710 | AM3STimeFormatAndNation formatAndNation; | ||
| 711 | formatAndNation = hourMode.intValue; | ||
| 712 | |||
| 713 | [[self getAM3SWithMac:mac]commandAM3SSetTimeFormatAndNation:hourMode.intValue withFinishResult:^(BOOL resetSuc) { | ||
| 714 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_hour_mode_success_am"}; | ||
| 715 | |||
| 716 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 717 | |||
| 718 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 719 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 720 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 721 | }]; | ||
| 722 | } | ||
| 723 | } | ||
| 724 | #pragma mark-得到小时制 | ||
| 725 | RCT_EXPORT_METHOD(getHourMode:(nonnull NSString *)mac){ | ||
| 726 | |||
| 727 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 728 | |||
| 729 | [[self getAM3SWithMac:mac] commandAM3SGetTimeFormatAndNation:^(AM3STimeFormatAndNation timeFormatAndNation) { | ||
| 730 | |||
| 731 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_hour_mode_am",@"hourtype":[NSNumber numberWithInt:timeFormatAndNation]}; | ||
| 732 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 733 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 734 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 735 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 736 | }]; | ||
| 737 | } | ||
| 738 | } | ||
| 739 | |||
| 740 | #pragma mark-设置图片 | ||
| 741 | RCT_EXPORT_METHOD(setPicture:(nonnull NSString *)mac :(nonnull NSNumber *)index){ | ||
| 742 | |||
| 743 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 744 | |||
| 745 | |||
| 746 | if((index.intValue !=0) && (index.intValue !=1)){ | ||
| 747 | |||
| 748 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:400]}; | ||
| 749 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 750 | return; | ||
| 751 | } | ||
| 752 | |||
| 753 | |||
| 754 | AM3SPicture piction; | ||
| 755 | piction = index.intValue; | ||
| 756 | |||
| 757 | [[self getAM3SWithMac:mac] commandAM3SSetPicture:piction withFinishResult:^(BOOL resetSuc) { | ||
| 758 | |||
| 759 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_picture_success_am"}; | ||
| 760 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 761 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 762 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 763 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 764 | }]; | ||
| 765 | } | ||
| 766 | } | ||
| 767 | |||
| 768 | #pragma mark-得到图片 | ||
| 769 | RCT_EXPORT_METHOD(getPicture:(nonnull NSString *)mac){ | ||
| 770 | |||
| 771 | if ([self getAM3SWithMac:mac]!=nil) { | ||
| 772 | |||
| 773 | [[self getAM3SWithMac:mac] commandAM3SGetPicture:^(AM3SPicture picture) { | ||
| 774 | |||
| 775 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_picture_am",@"get_picture_am":[NSNumber numberWithInt:picture]}; | ||
| 776 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 777 | } withErrorBlock:^(AM3SErrorID errorID) { | ||
| 778 | NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]}; | ||
| 779 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 780 | }]; | ||
| 781 | } | ||
| 782 | } | ||
| 783 | |||
| 784 | |||
| 785 | |||
| 786 | |||
| 787 | |||
| 788 | @end | ||
