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