From 60bb4ce8d3ef0f8a324c6844cc990405de5d2e0f Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期五, 05 三月 2021 11:06:13 +0800
Subject: [PATCH] 2021-03-05 1.更新

---
 Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/UIViewControllers/EZWifiConfigViewController.m |  255 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 160 insertions(+), 95 deletions(-)

diff --git a/Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/UIViewControllers/EZWifiConfigViewController.m b/Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/UIViewControllers/EZWifiConfigViewController.m
index 19adcb3..6a410db 100644
--- a/Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/UIViewControllers/EZWifiConfigViewController.m
+++ b/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", @"钀ゅ皬鐭虫鍦ㄥ姫鍔涜繛鎺i-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

--
Gitblit v1.8.0