萤石云 iOSSDK,移植跨平台相关工程
JLChen
2021-03-05 60bb4ce8d3ef0f8a324c6844cc990405de5d2e0f
Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/UIViewControllers/EZWifiConfigViewController.m
@@ -89,14 +89,14 @@
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
 #pragma mark - Navigation
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
#pragma mark - UIAlertViewDelgate Methods
@@ -107,11 +107,18 @@
        self.enState = STATE_PLAT;
        [self createTimerWithTimeOut:30];
        [GlobalKit shareKit].deviceVerifyCode = [alertView textFieldAtIndex:0].text;
        [EZOPENSDK addDevice:[GlobalKit shareKit].deviceSerialNo
                  verifyCode:[GlobalKit shareKit].deviceVerifyCode
                  completion:^(NSError *error) {
                      [self handleTheError:error];
                  }];
        //        [EZOPENSDK addDevice:[GlobalKit shareKit].deviceSerialNo
        //                  verifyCode:[GlobalKit shareKit].deviceVerifyCode
        //                  completion:^(NSError *error) {
        //                      [self handleTheError:error];
        //                  }];
        //2021-03-03 添加设备的方法都修改成河东的接口方法
        [EZHttpUtil.sharedManager addDeviceByHDL:[GlobalKit shareKit].deviceSerialNo
                        verifyCode:[GlobalKit shareKit].deviceVerifyCode
                        completion:^(ResponseData *responseData) {
            //                       [hud hide:YES];
            [self handleTheError:responseData];
        }];
    }
    else if (alertView.tag == 0xbb && buttonIndex == 1)
    {
@@ -133,58 +140,63 @@
        NSInteger mode = 0;
        mode |= self.supportSmartMode?EZWiFiConfigSmart:0;
        mode |= self.supportSoundMode?EZWiFiConfigWave:0;
        __weak typeof(self) weakSelf = self;
        [EZOPENSDK startConfigWifi:weakSelf.ssid
                          password:weakSelf.password
                      deviceSerial:[GlobalKit shareKit].deviceSerialNo
                              mode:mode
                      deviceStatus:^(EZWifiConfigStatus status, NSString *deviceSerial) {
                          if (status == DEVICE_WIFI_CONNECTING)
                          {
                              weakSelf.enState = STATE_NONE;
                              [weakSelf createTimerWithTimeOut:60];
                          }
                          else if (status == DEVICE_WIFI_CONNECTED)
                          {
                              if(weakSelf.enState != STATE_WIFI){
                                  weakSelf.enState = STATE_WIFI;
                                  [weakSelf createTimerWithTimeOut:60];
                              }
                          }
                          else if (status == DEVICE_PLATFORM_REGISTED)
                          {
                              weakSelf.enState = STATE_PLAT;
                              [weakSelf createTimerWithTimeOut:30];
                              if([GlobalKit shareKit].deviceVerifyCode != nil)
                              {
                                  [EZOPENSDK addDevice:[GlobalKit shareKit].deviceSerialNo
                                            verifyCode:[GlobalKit shareKit].deviceVerifyCode
                                            completion:^(NSError *error) {
                                                [weakSelf handleTheError:error];
                                            }];
                              }
                              else
                              {
                                  UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"device_input_vierify_code", @"请输入设备验证码") message:@"" delegate:weakSelf cancelButtonTitle:NSLocalizedString(@"cancel",@"取消") otherButtonTitles:NSLocalizedString(@"done",@"确定"), nil];
                                  alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
                                  alertView.tag = 0xaa;
                                  [alertView show];
                                  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                      if ([_countTimer isValid])
                                      {
                                          [_countTimer invalidate];
                                          _countTimer = nil;
                                      }
                                  });
                              }
                          }
                      }];
            if (status == DEVICE_WIFI_CONNECTING)
            {
                weakSelf.enState = STATE_NONE;
                [weakSelf createTimerWithTimeOut:60];
            }
            else if (status == DEVICE_WIFI_CONNECTED)
            {
                if(weakSelf.enState != STATE_WIFI){
                    weakSelf.enState = STATE_WIFI;
                    [weakSelf createTimerWithTimeOut:60];
                }
            }
            else if (status == DEVICE_PLATFORM_REGISTED)
            {
                weakSelf.enState = STATE_PLAT;
                [weakSelf createTimerWithTimeOut:30];
                if([GlobalKit shareKit].deviceVerifyCode != nil)
                {
                    //                                  [EZOPENSDK addDevice:[GlobalKit shareKit].deviceSerialNo
                    //                                            verifyCode:[GlobalKit shareKit].deviceVerifyCode
                    //                                            completion:^(NSError *error) {
                    //                                                [weakSelf handleTheError:error];
                    //                                            }];
                    [EZHttpUtil.sharedManager addDeviceByHDL:[GlobalKit shareKit].deviceSerialNo
                                    verifyCode:[GlobalKit shareKit].deviceVerifyCode
                                    completion:^(ResponseData *responseData) {
                        [weakSelf handleTheError:responseData];
                    }];
                }
                else
                {
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"device_input_vierify_code", @"请输入设备验证码") message:@"" delegate:weakSelf cancelButtonTitle:NSLocalizedString(@"cancel",@"取消") otherButtonTitles:NSLocalizedString(@"done",@"确定"), nil];
                    alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
                    alertView.tag = 0xaa;
                    [alertView show];
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        if ([_countTimer isValid])
                        {
                            [_countTimer invalidate];
                            _countTimer = nil;
                        }
                    });
                }
            }
        }];
    }
    else
    {
        [self createAddDeviceInitView];
        _enState = STATE_SUCC;
        [self showTipsView];
    }
@@ -232,37 +244,52 @@
        [EZOPENSDK probeDeviceInfo:[GlobalKit shareKit].deviceSerialNo
                        deviceType:[GlobalKit shareKit].deviceModel
                        completion:^(EZProbeDeviceInfo *deviceInfo, NSError *error) {
                            if (error)
                            {
                                //有错误直接显示错误的UI
                                [self showFailedView];
                            }
                            else
                            {
                                if ([GlobalKit shareKit].deviceVerifyCode != nil)
                                {
                                    [EZOPENSDK addDevice:[GlobalKit shareKit].deviceSerialNo
                                              verifyCode:[GlobalKit shareKit].deviceVerifyCode
                                              completion:^(NSError *error) {
                                                  if (!error)
                                                  {
                                                      [self handleTheError:error];
                                                  }
                                                  else
                                                  {
                                                      [self showFailedView];
                                                  }
                                              }];
                                }
                                else
                                {
                                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"device_input_vierify_code", @"请输入设备验证码") message:@"" delegate:self cancelButtonTitle:NSLocalizedString(@"cancel",@"取消") otherButtonTitles:NSLocalizedString(@"done",@"确定"), nil];
                                    alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
                                    alertView.tag = 0xaa;
                                    [alertView show];
                                }
                            }
                        }];
            if (error)
            {
                //有错误直接显示错误的UI
                [self showFailedView];
            }
            else
            {
                if ([GlobalKit shareKit].deviceVerifyCode != nil)
                {
                    //                                    [EZOPENSDK addDevice:[GlobalKit shareKit].deviceSerialNo
                    //                                              verifyCode:[GlobalKit shareKit].deviceVerifyCode
                    //                                              completion:^(NSError *error) {
                    //                                                  if (!error)
                    //                                                  {
                    //                                                      [self handleTheError:error];
                    //                                                  }
                    //                                                  else
                    //                                                  {
                    //                                                      [self showFailedView];
                    //                                                  }
                    //                                              }];
                    [EZHttpUtil.sharedManager addDeviceByHDL:[GlobalKit shareKit].deviceSerialNo
                                    verifyCode:[GlobalKit shareKit].deviceVerifyCode
                                    completion:^(ResponseData *responseData) {
                        if (responseData.success)
                        {
                            [self handleTheError:responseData];
                        }
                        else
                        {
                            [self showFailedView];
                        }
                    }];
                }
                else
                {
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"device_input_vierify_code", @"请输入设备验证码") message:@"" delegate:self cancelButtonTitle:NSLocalizedString(@"cancel",@"取消") otherButtonTitles:NSLocalizedString(@"done",@"确定"), nil];
                    alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
                    alertView.tag = 0xaa;
                    [alertView show];
                }
            }
        }];
    }
    
    UILabel *timeLabel = (UILabel *)[self.timerImageView viewWithTag:0x11c];
@@ -417,10 +444,10 @@
            
            self.registerLabel.font = [UIFont systemFontOfSize:15.0f];
            self.registerLabel.textColor = [UIColor dd_hexStringToColor:@"0x666666"];
            self.bindLabel.font = [UIFont systemFontOfSize:15.0f];
            self.bindLabel.textColor = [UIColor dd_hexStringToColor:@"0x666666"];
            self.wifiLabel.text = NSLocalizedString(@"wifi_connecting_net", @"萤小石正在努力连接Wi-Fi网络");
            self.registerLabel.text = NSLocalizedString(@"wifi_register_server", @"注册平台服务器");
            self.bindLabel.text = NSLocalizedString(@"wifi_bind_account", @"绑定你的账号");
@@ -672,7 +699,7 @@
        case STATE_PLAT:
        {
            failedLab.text = NSLocalizedString(@"wifi_bind_fail", @"Wi-Fi配置成功,绑定账号失败,请重试");
            self.animationImageView.image = [UIImage imageNamed:@"failure_account"];//设备绑定失败
        }
            break;
@@ -683,11 +710,50 @@
    self.failedTipsView.hidden = NO;
}
- (void)handleTheError:(NSError *)error
//- (void)handleTheError:(NSError *)error
//{
//    [EZOPENSDK stopConfigWifi];
//
//    if (!error)
//    {
//        if ([_countTimer isValid])
//        {
//            [_countTimer invalidate];
//            _countTimer = nil;
//        }
//        _enState = STATE_SUCC;
//        [self showTipsView];
//        return;
//    }
//
//    if (error.code == 120010)
//    {
//        UIAlertView *retryAlertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"device_verify_code_wrong", @"验证码错误")
//                                                                 message:nil delegate:self
//                                                       cancelButtonTitle:NSLocalizedString(@"cancel", @"取消")
//                                                       otherButtonTitles:NSLocalizedString(@"retry", @"重试"), nil];
//        retryAlertView.tag = 0xbb;
//        [retryAlertView show];
//    }
//    else if (error.code == 120020)
//    {
//        [UIView dd_showMessage:NSLocalizedString(@"ad_already_added", @"您已添加过此设备")];
//    }
//    else if (error.code == 120022)
//    {
//        [UIView dd_showMessage:NSLocalizedString(@"ad_added_by_others", @"此设备已被别人添加")];
//    }
//    else
//    {
//        [UIView dd_showMessage:NSLocalizedString(@"wifi_add_fail", @"添加失败")];
//    }
//}
- (void)handleTheError:(ResponseData *)responseData
{
    [EZOPENSDK stopConfigWifi];
    
    if (!error)
    if (responseData.success)
    {
        if ([_countTimer isValid])
        {
@@ -699,7 +765,7 @@
        return;
    }
    
    if (error.code == 120010)
    if ([responseData.code isEqual: @"20010"])
    {
        UIAlertView *retryAlertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"device_verify_code_wrong", @"验证码错误")
                                                                 message:nil delegate:self
@@ -708,11 +774,11 @@
        retryAlertView.tag = 0xbb;
        [retryAlertView show];
    }
    else if (error.code == 120020)
    else if ([responseData.code isEqual: @"20017"])
    {
        [UIView dd_showMessage:NSLocalizedString(@"ad_already_added", @"您已添加过此设备")];
    }
    else if (error.code == 120022)
    else if ([responseData.code isEqual: @"20013"])
    {
        [UIView dd_showMessage:NSLocalizedString(@"ad_added_by_others", @"此设备已被别人添加")];
    }
@@ -721,7 +787,6 @@
        [UIView dd_showMessage:NSLocalizedString(@"wifi_add_fail", @"添加失败")];
    }
}
#pragma mark - Action Methods
- (void)completionButtonClicked:(id)sender