优化设置连接和重置设备过程
This commit is contained in:
parent
8c5623acdc
commit
d59ca3bb80
|
|
@ -11,10 +11,14 @@
|
|||
#import "ConnectHotspotTipViewController.h"
|
||||
#import "DeviceCameraModel.h"
|
||||
#import "DeviceModel.h"
|
||||
#import "MBProgressHUD.h"
|
||||
#import<SystemConfiguration/CaptiveNetwork.h>
|
||||
|
||||
@interface SettingResetViewController ()<IFishHotpotUDPHelperDelegate>
|
||||
|
||||
@property (nonatomic, strong) DeviceModel *currentDevice;
|
||||
@property (nonatomic, strong) MBProgressHUD *HUD;
|
||||
@property (nonatomic, assign) BOOL isDeleteingDevice;
|
||||
|
||||
@end
|
||||
|
||||
|
|
@ -27,6 +31,10 @@
|
|||
}
|
||||
|
||||
- (IBAction)reset:(id)sender {
|
||||
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) {
|
||||
[self.view makeToast:@"请先将手机连接到wifi:ifish-xxxx"];
|
||||
return;
|
||||
}
|
||||
[IFishHotpotUDPHelper sharedInstance].delegate = self;
|
||||
[[IFishHotpotUDPHelper sharedInstance] broadCastRestCommand];
|
||||
}
|
||||
|
|
@ -38,25 +46,64 @@
|
|||
#pragma mark - IFishHotpotUDPHelperDelegate
|
||||
|
||||
- (void)udpHelperCommandExecutedSuccess:(IFishUDPHelperBackMsgModel *)backModel {
|
||||
[self.view makeToast:@"设备即将重置"];
|
||||
|
||||
NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
|
||||
[deviceArry enumerateObjectsUsingBlock:^(DeviceModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([obj.macAddress isEqualToString:backModel.senderMacAddress]) {
|
||||
self.currentDevice = obj;
|
||||
self.HUD.labelText = @"设备即将重置";
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
|
||||
[deviceArry enumerateObjectsUsingBlock:^(DeviceModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([obj.macAddress isEqualToString:backModel.senderMacAddress]) {
|
||||
self.currentDevice = obj;
|
||||
self.HUD.labelText = @"请切当前Ifish-xxxx到其他网络,以进行后续操作";
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
|
||||
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
||||
BOOL networkOk = NO;
|
||||
if (status == AFNetworkReachabilityStatusReachableViaWiFi) {
|
||||
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) {
|
||||
networkOk = YES;
|
||||
}
|
||||
} else if (status == AFNetworkReachabilityStatusReachableViaWWAN) {
|
||||
networkOk = YES;
|
||||
}
|
||||
if (!networkOk) {
|
||||
return;
|
||||
}
|
||||
if (self.isDeleteingDevice) {
|
||||
return;
|
||||
}
|
||||
self.isDeleteingDevice = YES;
|
||||
[self deletDevice];
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
}];
|
||||
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)udpHelperMessage:(NSString *)msg {
|
||||
[self.view makeToast:msg];
|
||||
self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
||||
self.HUD.mode = MBProgressHUDModeIndeterminate;
|
||||
self.HUD.labelText = msg;
|
||||
}
|
||||
|
||||
#pragma mark - 删除设备
|
||||
|
||||
- (NSString *)currentWifiSSID {
|
||||
NSString *ssid = @"Not Found";
|
||||
CFArrayRef myArray = CNCopySupportedInterfaces();
|
||||
if (myArray != nil) {
|
||||
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
|
||||
if (myDict != nil) {
|
||||
NSDictionary *dict = (NSDictionary *)CFBridgingRelease(myDict);
|
||||
ssid = [dict valueForKey:@"SSID"];
|
||||
}
|
||||
}
|
||||
return ssid;
|
||||
}
|
||||
|
||||
-(void)deletDevice{
|
||||
self.HUD.labelText = @"开始删除设备";
|
||||
//先判断此设备是否有关联 摄像头
|
||||
//DeviceModel*deviceModel=[_deviceArr objectAtIndex:indexpath.row];
|
||||
//要删除的设设备id
|
||||
|
|
@ -85,37 +132,33 @@
|
|||
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
|
||||
NSLog(@"result:%@",resultDic[@"result"]);
|
||||
if ([resultDic[@"result"] isEqualToString:@"100"]) {
|
||||
[self showTitle:@"" messsage:@"删除成功"];
|
||||
self.HUD.labelText = @"删除成功";
|
||||
//重置数据库
|
||||
NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
|
||||
NSMutableArray *newArr = [NSMutableArray arrayWithArray:deviceArry];
|
||||
|
||||
for (DeviceModel *model in deviceArry) {
|
||||
|
||||
if ([model.deviceId isEqual:self.currentDevice.deviceId]) {
|
||||
|
||||
[newArr removeObject:model];
|
||||
|
||||
}
|
||||
}
|
||||
[[DataCenter defaultDtacenter] setValue: newArr forKey:@"deviceInfo"];
|
||||
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
|
||||
|
||||
[self showTitle:@"" messsage:@"删除失败"];
|
||||
|
||||
self.HUD.labelText = @"删除失败";
|
||||
}else if ([resultDic[@"result"] isEqualToString:@"301"]){
|
||||
|
||||
[self showTitle:@"" messsage:@"请求验证失败,请重新登陆"];
|
||||
|
||||
self.HUD.labelText = @"请求验证失败,请重新登陆";
|
||||
}else if ([resultDic[@"result"] isEqualToString:@"302"]){
|
||||
|
||||
[self showTitle:@"" messsage:@"请求被舍弃,未执行"];
|
||||
self.HUD.labelText = @"请求被舍弃,未执行";
|
||||
}
|
||||
[self.HUD hide:YES afterDelay:2];
|
||||
} else {
|
||||
self.HUD.labelText = @"删除失败";
|
||||
[self.HUD hide:YES afterDelay:2];
|
||||
}
|
||||
|
||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||
|
||||
[self showTitle:@"" messsage:@"请求异常"];
|
||||
self.HUD.labelText = @"请求异常";
|
||||
[self.HUD hide:YES afterDelay:2];
|
||||
}];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#import "ESPTouchResult.h"
|
||||
#import "ESPTouchTask.h"
|
||||
#import "IfishDataUnity.h"
|
||||
#import "MBProgressHUD.h"
|
||||
|
||||
@interface ConnectHotpotViewController ()<UITextFieldDelegate, IFishHotpotUDPHelperDelegate>
|
||||
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
|
||||
|
|
@ -26,6 +27,8 @@
|
|||
|
||||
@property (nonatomic, strong) NSMutableString *trackString;
|
||||
|
||||
@property (nonatomic, strong) MBProgressHUD *HUD;
|
||||
|
||||
/**
|
||||
设备返回的mac地址
|
||||
*/
|
||||
|
|
@ -155,11 +158,13 @@
|
|||
|
||||
- (void)udpHelperCommandExecutedSuccess:(IFishUDPHelperBackMsgModel *)backModel {
|
||||
self.ssid = backModel.senderMacAddress;
|
||||
[self.view makeToast:[NSString stringWithFormat:@"连接设置成功,切换当前热点连接到其他网络"]];
|
||||
|
||||
self.HUD.labelText = @"请切当前Ifish-xxxx到其他网络,以进行后续操作";
|
||||
self.trackString = [NSMutableString string];
|
||||
[self appendTrakContent:@"=================收到设备答复==================="];
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"答复状态码:%@", backModel.result]];
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"答复Mac地址:%@", backModel.senderMacAddress]];
|
||||
[IFishHotpotUDPHelper sharedInstance].delegate = nil;
|
||||
[[IFishHotpotUDPHelper sharedInstance] broadCastRestartCommand];
|
||||
self.macAddress = backModel.senderMacAddress;
|
||||
|
||||
|
|
@ -188,7 +193,9 @@
|
|||
}
|
||||
|
||||
- (void)udpHelperMessage:(NSString *)msg {
|
||||
[self.view makeToast:msg];
|
||||
self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
||||
self.HUD.mode = MBProgressHUDModeIndeterminate;
|
||||
self.HUD.labelText = msg;
|
||||
}
|
||||
|
||||
#pragma mark - bind
|
||||
|
|
@ -196,7 +203,7 @@
|
|||
NSLog(@"设备bssid_%@",bssid);
|
||||
[self appendTrakContent:@"=================进入绑定函数================="];
|
||||
NSString *userId = [dataContorl dataControlGetUserIdInfo];
|
||||
[self.view makeToast:[NSString stringWithFormat:@"正在绑定设备,bssid:%@", bssid]];
|
||||
self.HUD.labelText = @"开始绑定设备";
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"绑定参数 userID:%@", userId]];
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"绑定参数 macaddress:%@", bssid]];
|
||||
[AFHttpTool bindDeviceWithUserId:userId macAddress:bssid success:^(id response) {
|
||||
|
|
@ -213,8 +220,7 @@
|
|||
[self appendTrakContent:[NSString stringWithFormat:@"绑定返回状态码正确。设备信息为:%@", dataDic]];
|
||||
|
||||
if (!devicemodel.type){
|
||||
|
||||
[self.view makeToast:@"用户绑定设备成功,但设备初次入网失败请重新登陆"];
|
||||
self.HUD.labelText = @"用户绑定设备成功,但设备初次入网失败请重新登陆";
|
||||
|
||||
}else{
|
||||
NSMutableArray * _deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
|
||||
|
|
@ -226,10 +232,10 @@
|
|||
if ([devicemodel.type isEqual:[NSNull null]]){
|
||||
|
||||
//进入此循环 可能因为设备所在服务器 不在 本程序所在 服务器
|
||||
[self showTitle:@"" messsage:@"设备不在服务器"];
|
||||
self.HUD.labelText = @"设备不在服务器";
|
||||
|
||||
}else{
|
||||
[self.view makeToast:@"设备绑定成功"];
|
||||
self.HUD.labelText = @"设备绑定成功";
|
||||
[[IfishDataUnity shareDataInstance] initAppCenterVcWith:devicemodel addWithdissMisVc:nil];
|
||||
|
||||
//绑定成功 加 经验值
|
||||
|
|
@ -239,27 +245,28 @@
|
|||
|
||||
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
|
||||
[self appendTrakContent:@"绑定返回状态码错误。设备信息为:%@"];
|
||||
|
||||
[self.view makeToast:@"绑定失败"];
|
||||
self.HUD.labelText = @"绑定失败";
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
|
||||
}else if ([resultDic[@"result"] isEqualToString:@"301"]){
|
||||
[self appendTrakContent:@"绑定返回状态码错误。设备信息为:%@"];
|
||||
|
||||
[self.view makeToast:@"请求验证失败,请重新登录"];
|
||||
self.HUD.labelText = @"请求验证失败,请重新登录";
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
}else if ([resultDic[@"result"] isEqualToString:@"302"]){
|
||||
// 请求被舍弃未执行
|
||||
[self appendTrakContent:@"绑定返回状态码错误。设备信息为:%@"];
|
||||
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
[self.view makeToast:@"绑定失败"];
|
||||
self.HUD.labelText = @"绑定失败";
|
||||
[self.HUD hide:YES afterDelay:2];
|
||||
}
|
||||
|
||||
|
||||
} failure:^(NSError *err) {
|
||||
self.isBindingDevice = NO;
|
||||
[self.view makeToast:@"网络异常"];
|
||||
self.HUD.labelText = @"网络异常";
|
||||
[self.HUD hide:YES afterDelay:2];
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"绑定网络请求错误:%@", err.localizedDescription]];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue