airkiss连接
This commit is contained in:
@@ -9,6 +9,11 @@
|
||||
#import "LXWaveProgressView.h"
|
||||
#import "StoreNameView.h"
|
||||
#import "EspTouchDelegateImpl.h"
|
||||
|
||||
#import "JMAirKiss.h"
|
||||
#import "HUDTools.h"
|
||||
#import <NetworkExtension/NetworkExtension.h>
|
||||
#import <CoreLocation/CoreLocation.h>
|
||||
@interface ConfigWifiViewController : BaseViewController
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UILabel *wifiNamelabel;
|
||||
|
||||
@@ -57,6 +57,7 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
|
||||
@property(nonatomic,strong) UILabel *maclabel;
|
||||
|
||||
@property(nonatomic,strong)IfishConnectingView *connectingView;
|
||||
@property (nonatomic, strong) JMAirKissConnection *airKissConnection; ;
|
||||
|
||||
Strong CLLocationManager *locationManager;//iOS13,获取WiFi名称必须开启定位权限
|
||||
|
||||
@@ -65,7 +66,14 @@ Strong CLLocationManager *locationManager;//iOS13,获取WiFi名称必须开启
|
||||
extern BOOL isfromCameraView;
|
||||
|
||||
@implementation ConfigWifiViewController
|
||||
|
||||
-(JMAirKissConnection *)airKissConnection
|
||||
{
|
||||
if(!_airKissConnection)
|
||||
{
|
||||
_airKissConnection= [[JMAirKissConnection alloc]init];
|
||||
}
|
||||
return _airKissConnection;
|
||||
}
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view from its nib.
|
||||
@@ -79,14 +87,14 @@ extern BOOL isfromCameraView;
|
||||
_wifiTextFiled.delegate=self;
|
||||
_wifiTextFiled.layer.masksToBounds=YES;
|
||||
_wifiTextFiled.layer.cornerRadius=5;
|
||||
if (@available(iOS 13.0, *)){//iOS13之后,设置颜色的方便变更
|
||||
|
||||
}else{
|
||||
[_wifiTextFiled setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
|
||||
}
|
||||
UIView*phoneView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 9, 10)];
|
||||
self.wifiTextFiled.leftView=phoneView;
|
||||
self.wifiTextFiled.textColor = RGB_51;
|
||||
// if (@available(iOS 13.0, *)){//iOS13之后,设置颜色的方便变更
|
||||
//
|
||||
// }else{
|
||||
// [_wifiTextFiled setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
|
||||
// }
|
||||
// UIView*phoneView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 9, 10)];
|
||||
// self.wifiTextFiled.leftView=phoneView;
|
||||
// self.wifiTextFiled.textColor = RGB_51;
|
||||
self.wifiTextFiled.leftViewMode=UITextFieldViewModeAlways;
|
||||
|
||||
[self addTitleViewWithTitle:self.vcTitle];
|
||||
@@ -533,126 +541,149 @@ extern BOOL isfromCameraView;
|
||||
- (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 = 100000;
|
||||
if ([firstResult isSuc])
|
||||
{
|
||||
|
||||
_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.lodviewMissStyle=lodingViewdissMissAlreadyBinded;
|
||||
[self mmPogressHUDdismiss];
|
||||
[self connectNormalView];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
//[self.navigationController popViewControllerAnimated:YES];
|
||||
[self.view makeToast:@"该设备已存在"];
|
||||
|
||||
}else{
|
||||
|
||||
if (self.deviceType==DEVICEPETS) {
|
||||
[self showStoreNameView];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self bindDeviceWithSsid:_deviceBssid];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// else{
|
||||
//
|
||||
// [self.view makeToast:@"您的设备数量已超过限制"];
|
||||
// [self mmPogressHUDdismiss];
|
||||
// [self connectNormalView];
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
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)]];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void(^success)(NSString*deviceBssid)=^(NSString*deviceBssid)
|
||||
{
|
||||
|
||||
_deviceBssid=deviceBssid;
|
||||
|
||||
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.lodviewMissStyle=lodingViewdissMissAlreadyBinded;
|
||||
[self mmPogressHUDdismiss];
|
||||
[self connectNormalView];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
//[self.navigationController popViewControllerAnimated:YES];
|
||||
[self.view makeToast:@"该设备已存在"];
|
||||
|
||||
}else{
|
||||
|
||||
if (self.deviceType==DEVICEPETS) {
|
||||
[self showStoreNameView];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
self.lodviewMissStyle=lodingViewdissMissfail;
|
||||
[self mmPogressHUDdismiss];
|
||||
[self connectNormalView];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
[self.view makeToast:@"未获取到设备mac"];
|
||||
|
||||
[self bindDeviceWithSsid:_deviceBssid];
|
||||
}
|
||||
}
|
||||
else if(firstResult.isCancelled)
|
||||
{
|
||||
self.lodviewMissStyle=lodingViewdissMissfail;
|
||||
[self mmPogressHUDdismiss];
|
||||
[self connectNormalView];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
[self.view makeToast:@"连接被取消"];
|
||||
|
||||
|
||||
}
|
||||
|
||||
else if(!esptouchResultArray.count)
|
||||
{
|
||||
self.lodviewMissStyle=lodingViewdissMissfail;
|
||||
[self mmPogressHUDdismiss];
|
||||
[self connectNormalView];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
[self.view makeToast:@"未有设备响应"];
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
void(^failure)(NSError*error,NSString*msg)=^(NSError*error,NSString*msg)
|
||||
{
|
||||
self.lodviewMissStyle=lodingViewdissMissfail;
|
||||
[self mmPogressHUDdismiss];
|
||||
[self connectNormalView];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
if(msg.length)
|
||||
{
|
||||
[self.view makeToast:msg];
|
||||
}
|
||||
|
||||
};
|
||||
ConnectType type = self.connectType;
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
if(type == ConnectTypeAirKiss)
|
||||
{
|
||||
self.airKissConnection.connectionSuccess = success;
|
||||
self.airKissConnection.connectionFailure = ^{
|
||||
failure(nil,nil);
|
||||
};
|
||||
NSString *apSsid = self.ssid;
|
||||
NSString *apPwd = self.wifiTextFiled.text;
|
||||
[self.airKissConnection connectAirKissWithSSID:apSsid
|
||||
password:apPwd];
|
||||
}
|
||||
else if(type==ConnectTypeSmartESPTouch)
|
||||
{
|
||||
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 = 100000;
|
||||
if ([firstResult isSuc])
|
||||
{
|
||||
success(firstResult.bssid);
|
||||
|
||||
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
|
||||
{
|
||||
failure(nil,@"未获取到设备mac");
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else if(firstResult.isCancelled)
|
||||
{
|
||||
failure(nil,@"连接被取消");
|
||||
|
||||
|
||||
}
|
||||
|
||||
else if(!esptouchResultArray.count)
|
||||
{
|
||||
failure(nil,@"未有设备响应");
|
||||
[self.view makeToast:@"未有设备响应"];
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
else if (type == ConnectTypeAP)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
- (NSArray *) executeForResults
|
||||
|
||||
Reference in New Issue
Block a user