修改设备绑定过程

This commit is contained in:
xuemh
2018-08-08 21:12:29 +08:00
parent f8009af9c0
commit 0a2f673918
2 changed files with 13 additions and 101 deletions
@@ -134,8 +134,9 @@
#pragma mark - IFishHotpotUDPHelperDelegate
- (void)udpHelperCommandExecutedSuccess:(IFishUDPHelperBackMsgModel *)backModel {
self.ssid = backModel.senderMacAddress;
[self.view makeToast:[NSString stringWithFormat:@"连接设置成功,mac 地址:%@",backModel.senderMacAddress]];
[self tapConfirmForResults];
[self bindDeviceWithSsid:backModel.senderMacAddress];
}
- (void)udpHelperMessage:(NSString *)msg {
@@ -143,104 +144,6 @@
}
#pragma mark - bind
- (void) tapConfirmForResults{
NSLog(@"ViewController do confirm action...");
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSLog(@"ViewController do the execute work...");
// execute the task
NSArray *esptouchResultArray = [self executeForResults];
// show the result to the user in UI Main Thread
dispatch_async(dispatch_get_main_queue(), ^{
// [self._spinner stopAnimating];
// [self enableConfirmBtn];
ESPTouchResult *firstResult = [esptouchResultArray objectAtIndex:0];
// check whether the task is cancelled and no results received
if (!firstResult.isCancelled)
{
NSMutableString *mutableStr = [[NSMutableString alloc]init];
NSUInteger count = 0;
// max results to be displayed, if it is more than maxDisplayCount,
// just show the count of redundant ones
const int maxDisplayCount = 5;
if ([firstResult isSuc])
{
NSString * _deviceBssid=firstResult.bssid;
NSArray*arry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
DeviceModel*model=[[DeviceModel alloc]init];
if (arry.count<5) {
NSMutableArray*macdressArr=[[NSMutableArray alloc]init];
for (model in arry) {
[macdressArr addObject:model.macAddress];
}
BOOL exst=[macdressArr containsObject:_deviceBssid];
if (exst) {
self.bakbutton.userInteractionEnabled=YES;
//[self.navigationController popViewControllerAnimated:YES];
[self.view makeToast:@"该设备已存在"];
}else{
[self bindDeviceWithSsid:_deviceBssid];
}
}else{
[self.view makeToast:@"您的设备数量已超过限制"];
}
for (int i = 0; i < [esptouchResultArray count]; ++i)
{
ESPTouchResult *resultInArray = [esptouchResultArray objectAtIndex:i];
[mutableStr appendString:[resultInArray description]];
[mutableStr appendString:@"\n"];
count++;
if (count >= maxDisplayCount)
{
break;
}
}
if (count < [esptouchResultArray count])
{
[mutableStr appendString:[NSString stringWithFormat:@"\nthere's %lu more result(s) without showing\n",(unsigned long)([esptouchResultArray count] - count)]];
}
}
else
{
self.bakbutton.userInteractionEnabled=YES;
[self.view makeToast:@"未获取到设备mac"];
}
}
});
});
}
- (NSArray *) executeForResults
{
NSString *apSsid = self.ssid;
NSString *apPwd = self.pwdTf.text;
NSString *apBssid = self.bssid;
BOOL isSsidHidden = YES;
int taskCount=1;
self.epTask =
[[ESPTouchTask alloc]initWithApSsid:apSsid andApBssid:apBssid andApPwd:apPwd andIsSsidHiden:isSsidHidden];
NSArray * esptouchResults = [self.epTask executeForResults:taskCount];
NSLog(@"ViewController executeForResult() result is: %@",esptouchResults);
return esptouchResults;
}
-(void)bindDeviceWithSsid:(NSString*)bssid{
NSLog(@"设备bssid_%@",bssid);
NSString *userId = [dataContorl dataControlGetUserIdInfo];
@@ -292,7 +195,6 @@
// 请求被舍弃未执行
self.bakbutton.userInteractionEnabled=YES;
[self.view makeToast:@"绑定失败"];
}