优化设置连接和重置设备过程
This commit is contained in:
+67
-24
@@ -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];
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user