airkiss连接

This commit is contained in:
祝发冬
2023-08-20 12:16:19 +08:00
parent b2f5610e74
commit 28645e9c22
6 changed files with 464 additions and 120 deletions
BIN
View File
Binary file not shown.
+74
View File
@@ -0,0 +1,74 @@
//
// HUDTools.h
// AtsmartHome
//
// Created by shengxiao on 15/8/20.
// Copyright (c) 2015年 Atsmart. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "MBProgressHUD.h"
typedef void (^HUDCompletion) (void);
@interface HUDTools : NSObject
+ (MBProgressHUD *)showHUDWithLabel:(NSString *)labelText
onView:(UIView *)view;
+ (MBProgressHUD *)showHUDWithDetailLabel:(NSString *)detailLabelText
onView:(UIView *)view;
+ (MBProgressHUD *)showHUDOnWindowWithLabel:(NSString *)labelText;
+ (MBProgressHUD *)showHUDWithLabel:(NSString *)labelText
onView:(UIView *)view
color:(UIColor *)color;
+ (MBProgressHUD *)showHUDWithLabel:(NSString *)labelText
onView:(UIView *)view
color:(UIColor *)color
labelTextColor:(UIColor *)textColor
activityIndicatorColor:(UIColor *)actIndicatorColor;
+ (MBProgressHUD *)showHUDOnWindowWithLabel:(NSString *)labelText
color:(UIColor *)color;
+ (MBProgressHUD *)showTransparentHUDWithLabel:(NSString *)labelText
onView:(UIView *)view;
+ (MBProgressHUD *)showTransparentHUDOnWindowWithLabel:(NSString *)labelText
labelTextColor:(UIColor *)textColor;
+ (MBProgressHUD *)showTransparentHUDOnWindowWithLabel:(NSString *)labelText;
+ (MBProgressHUD *)changeLabelText:(NSString *)labelText;
+ (MBProgressHUD *)changeDetailLabelText:(NSString *)labelText;
+ (void)removeHUD;
+ (void)removeHUDWithDelay:(float)time;
+ (void)removeHUDWithDelay:(float)time
completion:(HUDCompletion)completion;
+ (void)showText:(NSString *)text
onView:(UIView *)view
delay:(float)time;
+ (void)showText:(NSString *)text
onView:(UIView *)view
delay:(float)time
completion:(HUDCompletion)completion;
+ (void)showDetailText:(NSString *)text
onView:(UIView *)view
delay:(float)time;
+ (void)showDetailText:(NSString *)text
onView:(UIView *)view
delay:(float)time
completion:(HUDCompletion)completion;
@end
+226
View File
@@ -0,0 +1,226 @@
//
// HUDTools.m
// AtsmartHome
//
// Created by shengxiao on 15/8/20.
// Copyright (c) 2015年 Atsmart. All rights reserved.
//
#import "HUDTools.h"
static MBProgressHUD *HUD;
static HUDCompletion _completion;
@implementation HUDTools
+ (MBProgressHUD *)showHUDWithLabel:(NSString *)labelText
onView:(UIView *)view {
HUD = [[MBProgressHUD alloc] initWithView:view];
[view addSubview:HUD];
HUD.labelText = labelText;
HUD.labelFont = [UIFont systemFontOfSize:16.0f];
[HUD show:YES];
return HUD;
}
+ (MBProgressHUD *)showHUDWithDetailLabel:(NSString *)detailLabelText
onView:(UIView *)view {
HUD = [[MBProgressHUD alloc] initWithView:view];
[view addSubview:HUD];
HUD.detailsLabelText = detailLabelText;
HUD.detailsLabelFont = [UIFont systemFontOfSize:16.0f];
[HUD show:YES];
return HUD;
}
+ (MBProgressHUD *)showHUDOnWindowWithLabel:(NSString *)labelText {
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
[[UIApplication sharedApplication].keyWindow addSubview:HUD];
HUD.labelText = labelText;
[HUD show:YES];
return HUD;
}
+ (MBProgressHUD *)showHUDWithLabel:(NSString *)labelText
onView:(UIView *)view
color:(UIColor *)color {
HUD = [self showHUDWithLabel:labelText
onView:view];
HUD.color = color;
return HUD;
}
+ (MBProgressHUD *)showHUDWithLabel:(NSString *)labelText
onView:(UIView *)view
color:(UIColor *)color
labelTextColor:(UIColor *)textColor
activityIndicatorColor:(UIColor *)actIndicatorColor {
HUD = [self showHUDWithLabel:labelText
onView:view];
HUD.color = color;
HUD.activityIndicatorColor = actIndicatorColor;
HUD.labelColor = textColor;
return HUD;
}
+ (MBProgressHUD *)showHUDOnWindowWithLabel:(NSString *)labelText
color:(UIColor *)color {
HUD = [self showHUDOnWindowWithLabel:labelText];
HUD.color = color;
return HUD;
}
+ (MBProgressHUD *)showTransparentHUDWithLabel:(NSString *)labelText
onView:(UIView *)view {
HUD = [self showHUDWithLabel:labelText
onView:view];
HUD.color = [UIColor clearColor];
return HUD;
}
+ (MBProgressHUD *)showTransparentHUDOnWindowWithLabel:(NSString *)labelText
labelTextColor:(UIColor *)textColor {
HUD = [self showHUDOnWindowWithLabel:labelText];
HUD.color = [UIColor clearColor];
HUD.labelColor = textColor;
return HUD;
}
+ (MBProgressHUD *)showTransparentHUDOnWindowWithLabel:(NSString *)labelText {
HUD = [self showHUDOnWindowWithLabel:labelText];
HUD.color = [UIColor clearColor];
return HUD;
}
+ (MBProgressHUD *)changeLabelText:(NSString *)labelText {
if (HUD == nil) {
return nil;
}
HUD.labelText = labelText;
return HUD;
}
+ (MBProgressHUD *)changeDetailLabelText:(NSString *)labelText {
if (HUD == nil) {
return nil;
}
HUD.detailsLabelText = labelText;
return HUD;
}
+ (void)removeHUD {
[HUD hide:YES afterDelay:0];
[HUD removeFromSuperViewOnHide];
}
+ (void)removeHUDWithDelay:(float)time {
[HUD hide:YES afterDelay:time];
[HUD removeFromSuperViewOnHide];
}
+ (void)removeHUDWithDelay:(float)time
completion:(HUDCompletion)completion {
[self removeHUDWithDelay:time];
_completion = completion;
[self performSelector:@selector(handleCompletionAction)
withObject:nil
afterDelay:time];
}
+ (void)showText:(NSString *)text
onView:(UIView *)view
delay:(float)time {
[self showText:text
onView:view
delay:time
completion:nil];
}
+ (void)showText:(NSString *)text
onView:(UIView *)view
delay:(float)time
completion:(HUDCompletion)completion {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
// Configure for text only and offset down
hud.mode = MBProgressHUDModeText;
hud.labelText = text;
hud.margin = 10.f;
hud.removeFromSuperViewOnHide = YES;
hud.labelFont = [UIFont systemFontOfSize:16.0f];
[hud hide:YES afterDelay:time];
if (completion != nil) {
_completion = completion;
[self performSelector:@selector(handleCompletionAction)
withObject:nil
afterDelay:time];
}
}
/**
*@description 显示详情信息(多行)
*@params <##>
*@return <##>
*/
+ (void)showDetailText:(NSString *)text
onView:(UIView *)view
delay:(float)time {
[self showDetailText:text
onView:view
delay:time
completion:nil];
}
+ (void)showDetailText:(NSString *)text
onView:(UIView *)view
delay:(float)time
completion:(HUDCompletion)completion {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
// Configure for text only and offset down
hud.mode = MBProgressHUDModeText;
hud.detailsLabelText = text;
hud.margin = 10.f;
hud.removeFromSuperViewOnHide = YES;
hud.detailsLabelFont = [UIFont systemFontOfSize:16.0f];
[hud hide:YES afterDelay:time];
if (completion != nil) {
_completion = completion;
[self performSelector:@selector(handleCompletionAction)
withObject:nil
afterDelay:time];
}
}
+ (void)handleCompletionAction {
if (_completion != nil) {
_completion();
_completion = nil;
}
}
@end
@@ -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