热点连接流程修改

This commit is contained in:
wbzhan
2019-09-21 17:29:16 +08:00
parent 9342faecbc
commit 41e5233e1f
65 changed files with 2363 additions and 651 deletions
@@ -0,0 +1,21 @@
//
// ConAquarChooseWiFiVC.h
// Ifish
//
// Created by wbzhan on 2019/9/20.
// Copyright © 2019 lianlian. All rights reserved.
//
#import "BaseViewController.h"
NS_ASSUME_NONNULL_BEGIN
/**
选取设备WiFi
*/
@interface ConAquarChooseWiFiVC : BaseViewController
Copy NSString *wifiName;
Copy NSString *wifiPwd;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,147 @@
//
// ConAquarChooseWiFiVC.m
// Ifish
//
// Created by wbzhan on 2019/9/20.
// Copyright © 2019 lianlian. All rights reserved.
//
#import "ConAquarChooseWiFiVC.h"
#import "ConnectingAquarVC.h"
#import <SystemConfiguration/CaptiveNetwork.h>
@interface ConAquarChooseWiFiVC ()
Strong UIImageView *topImage;
Strong UIButton *connectWiFiBtn;
Assign BOOL isGoChangeWiFi;//更换为设备的WiFi
@end
@implementation ConAquarChooseWiFiVC
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:Noti_WillEnterForeground object:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self addTitleViewWithTitle:@"选择设备WiFi"];
[self.view addSubview:self.topImage];
[self.view addSubview:self.connectWiFiBtn];
[self addContentLabel];
[self.topImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.mas_equalTo(self.view);
make.height.mas_equalTo(kSizeFrom750(424));
}];
[self.connectWiFiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.bottom.mas_equalTo(-kSizeFrom750(60));
make.width.mas_equalTo(kSizeFrom750(400));
make.height.mas_equalTo(kSizeFrom750(60));
}];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillEnterForeground:) name:Noti_WillEnterForeground object:nil];
// Do any additional setup after loading the view.
}
- (UIImageView *)topImage
{
if (!_topImage) {
_topImage = InitObject(UIImageView);
[_topImage setImage:IMAGEBYENAME(@"icons_con_topbg")];
}
return _topImage;
}
- (UIButton *)connectWiFiBtn{
if (!_connectWiFiBtn) {
_connectWiFiBtn = InitObject(UIButton);
[_connectWiFiBtn setTitle:@"去设置WiFi" forState:UIControlStateNormal];
[_connectWiFiBtn setBackgroundColor:RGB(88, 151, 231)];
[_connectWiFiBtn setTitleColor:XWhite forState:UIControlStateNormal];
[_connectWiFiBtn.titleLabel setFont:FontSize(14)];
_connectWiFiBtn.layer.cornerRadius = kSizeFrom750(10);
_connectWiFiBtn.layer.masksToBounds = YES;
[_connectWiFiBtn addTarget:self action:@selector(connectWiFiBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _connectWiFiBtn;
}
-(void)addContentLabel{
UILabel *preLabel;
NSArray *textArr = @[@"1.请将产品15秒内断电通电3次进入热点模式;",@"2.点击去设置:设置-WiFi-选择ifish-xxx的网络,输入密码12345678,连接好后返回爱奇鱼app。"];
for (int i=0; i<2; i++) {
UILabel *label = InitObject(UILabel);
label.text = textArr[i];
label.textColor = RGB_92;
label.font = FontSize(12);
label.numberOfLines = 0;
[self.view addSubview:label];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kSizeFrom750(60));
make.right.mas_equalTo(-kSizeFrom750(60));
if (preLabel==nil) {
make.top.mas_equalTo(self.topImage.mas_bottom).offset(kSizeFrom750(120));
} else {
make.top.mas_equalTo(preLabel.mas_bottom).offset(kSizeFrom750(30));
}
}];
preLabel = label;
}
}
//跳转到WiFi设置页面
-(void)connectWiFiBtnClick:(UIButton *)sender{
NSURL *url1 = [NSURL URLWithString:@"App-prefs:root=WIFI"];
if ([[UIApplication sharedApplication] canOpenURL:url1])
{
self.isGoChangeWiFi = YES;
[[UIApplication sharedApplication] openURL:url1];
}
}
-(void)checkWiFi{
// NSDictionary *ifs = [self getSSIDInfo];
// NSString *wifiName = [ifs objectForKey:@"SSID"];
// if ([wifiName rangeOfString:@"ifish-"].location!=NSNotFound) {
//wifi正确,则尝试连接设备
ConnectingAquarVC *connecting = InitObject(ConnectingAquarVC);
connecting.wifiName = self.wifiName;
connecting.wifiPassword = self.wifiPwd;
[self.navigationController pushViewController:connecting animated:YES];
// }else{
// [self.view makeToast:@"WiFi名称不匹配,请重试"];
// }
}
- (id)getSSIDInfo
{
NSArray *ifs = (id)CFBridgingRelease(CNCopySupportedInterfaces());
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
id info = nil;
for (NSString *ifnam in ifs) {
info = (id)CFBridgingRelease(CNCopyCurrentNetworkInfo((CFStringRef)ifnam));
if (info && [info count]) {
break;
}
}
return info ;
}
//即将进入前台
-(void)viewWillEnterForeground:(NSNotification *)noti{
if (self.isGoChangeWiFi) {
[self checkWiFi];
}
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
@@ -0,0 +1,20 @@
//
// ConAquarMethodVC.h
// Ifish
//
// Created by wbzhan on 2019/9/20.
// Copyright © 2019 lianlian. All rights reserved.
//
#import "BaseViewController.h"
NS_ASSUME_NONNULL_BEGIN
/**
水族箱连接方式选择
*/
@interface ConAquarMethodVC : BaseViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,111 @@
//
// ConAquarMethodVC.m
// Ifish
//
// Created by wbzhan on 2019/9/20.
// Copyright © 2019 lianlian. All rights reserved.
//
#import "ConAquarMethodVC.h"
#import "SecondConnectWifiController.h"
#import "ConAquarNowWiFiPwdVC.h"
@interface ConAquarMethodVC ()
Strong UILabel *subTitleLabel;
@end
@implementation ConAquarMethodVC
- (void)viewDidLoad {
[super viewDidLoad];
[self addTitleViewWithTitle:@"连接水族箱"];
[self.view addSubview:self.subTitleLabel];
NSArray *imageArr = @[@"icons_con_01",@"icons_con_02"];
NSArray *titleArr = @[@"智能连接",@"热点连接"];
for (int i=0; i<2; i++) {
UIButton *contentView = InitObject(UIButton);
[contentView addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
contentView.tag = i;
[self.view addSubview:contentView];
contentView.backgroundColor = XWhite;
contentView.layer.cornerRadius = kSizeFrom750(10);
contentView.layer.masksToBounds = YES;
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.width.mas_equalTo(kSizeFrom750(650));
make.height.mas_equalTo(kSizeFrom750(140));
make.top.mas_equalTo(self.subTitleLabel.mas_bottom).offset(kSizeFrom750(60)+i*kSizeFrom750(200));
}];
UIImageView *iconImage = InitObject(UIImageView);
[iconImage setImage:IMAGEBYENAME(imageArr[i])];
[contentView addSubview:iconImage];
[iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(contentView);
make.left.mas_equalTo(kSizeFrom750(50));
make.width.height.mas_equalTo(kSizeFrom750(84));
}];
UILabel *titleL = InitObject(UILabel);
titleL.text = titleArr[i];
titleL.textColor = RGB(130, 130, 130);
titleL.font = FontSize(18);
[contentView addSubview:titleL];
[titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(iconImage.mas_right).offset(kSizeFrom750(30));
make.centerY.mas_equalTo(iconImage);
}];
UIImageView *rightArrow = InitObject(UIImageView);
[rightArrow setImage:IMAGEBYENAME(@"right_arrow")];
[contentView addSubview:rightArrow];
[rightArrow mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(titleL);
make.right.mas_equalTo(-kSizeFrom750(30));
make.width.height.mas_equalTo(kSizeFrom750(44));
}];
}
self.view.backgroundColor = COLOR_Background;
// Do any additional setup after loading the view.
}
-(void)buttonClick:(UIButton *)sender{
self.hidesBottomBarWhenPushed = YES;
if (sender.tag==0) {
SecondConnectWifiController *wifivc=[[SecondConnectWifiController alloc]init];
wifivc.vcTitle=@"连接水族箱";
[self.navigationController pushViewController:wifivc animated:YES];
}else{
ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC);
[self.navigationController pushViewController:vc animated:YES];
}
}
- (UILabel *)subTitleLabel
{
if (!_subTitleLabel) {
_subTitleLabel = InitObject(UILabel);
_subTitleLabel.font = FontSize(16);
_subTitleLabel.text = @"请选择合适的连接方式";
_subTitleLabel.textColor = RGB_92;
}
return _subTitleLabel;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
@@ -0,0 +1,20 @@
//
// ConAquarNowWiFiPwdVC.h
// Ifish
//
// Created by wbzhan on 2019/9/20.
// Copyright © 2019 lianlian. All rights reserved.
//
#import "BaseViewController.h"
NS_ASSUME_NONNULL_BEGIN
/**
输入当前wifi密码页面
*/
@interface ConAquarNowWiFiPwdVC : BaseViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,225 @@
//
// ConAquarNowWiFiPwdVC.m
// Ifish
//
// Created by wbzhan on 2019/9/20.
// Copyright © 2019 lianlian. All rights reserved.
//
#import "ConAquarNowWiFiPwdVC.h"
#import <SystemConfiguration/CaptiveNetwork.h>
#import "ConAquarChooseWiFiVC.h"
#import "IQKeyboardManager.h"
@interface ConAquarNowWiFiPwdVC ()<UITextFieldDelegate>
Strong UILabel *titleL;
Strong UILabel *subTitleL;
Strong UITextField *wifiNameTextField;
Strong UITextField *wifiPwdTextField;
Strong UIButton *nextBtn;
@end
@implementation ConAquarNowWiFiPwdVC
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.wifiPwdTextField becomeFirstResponder];
[IQKeyboardManager sharedManager].enable = NO;
}
- (void)viewWillDisappear:(BOOL)animated{
[IQKeyboardManager sharedManager].enable = YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self addTitleViewWithTitle:@"连接网络"];
[self.view addSubview:self.titleL];
[self.view addSubview:self.subTitleL];
[self.view addSubview:self.wifiNameTextField];
[self.view addSubview:self.wifiPwdTextField];
[self.view addSubview:self.nextBtn];
[self loadLayout];
NSDictionary *ifs = [self getSSIDInfo];
self.wifiNameTextField.text = [ifs objectForKey:@"SSID"];
// Do any additional setup after loading the view.
}
- (UILabel *)titleL
{
if (!_titleL) {
_titleL = InitObject(UILabel);
_titleL.text = @"设备需要连接的WiFi";
_titleL.textAlignment = NSTextAlignmentCenter;
_titleL.font = FontSize(16);
_titleL.textColor = RGB_92;
}
return _titleL;
}
- (UILabel *)subTitleL
{
if (!_subTitleL) {
_subTitleL = InitObject(UILabel);
_subTitleL.text = @"设备暂不支持5G路由WiFi";
_subTitleL.textAlignment = NSTextAlignmentCenter;
_subTitleL.font = FontSize(12);
_subTitleL.textColor = RGB_92;
}
return _subTitleL;
}
- (UIButton *)nextBtn{
if (!_nextBtn) {
_nextBtn = InitObject(UIButton);
[_nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
[_nextBtn setBackgroundColor:RGB(88, 151, 231)];
[_nextBtn setTitleColor:XWhite forState:UIControlStateNormal];
[_nextBtn.titleLabel setFont:FontSize(14)];
_nextBtn.layer.cornerRadius = kSizeFrom750(10);
_nextBtn.layer.masksToBounds = YES;
[_nextBtn addTarget:self action:@selector(nextBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _nextBtn;
}
-(UITextField*)wifiNameTextField{
if (!_wifiNameTextField) {
_wifiNameTextField = InitObject(UITextField);
_wifiNameTextField.placeholder = @"请输入WiFi名称";
_wifiNameTextField.font = FontSize(14);
_wifiNameTextField.delegate = self;
_wifiNameTextField.backgroundColor = XWhite;
_wifiNameTextField.layer.masksToBounds = YES;
_wifiNameTextField.layer.cornerRadius = kSizeFrom750(10);
_wifiNameTextField.leftViewMode = UITextFieldViewModeAlways;
UIView *leftView = InitObject(UIView);
leftView.frame = RECT(0, 0, kSizeFrom750(90), kSizeFrom750(90));
UIImageView *leftImage = [[UIImageView alloc] init];
[leftView addSubview:leftImage];
[leftImage setImage:IMAGEBYENAME(@"icons_con_wifi")];
[leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(leftView);
make.width.height.mas_equalTo(kSizeFrom750(50));
}];
_wifiNameTextField.leftView = leftView;
}
return _wifiNameTextField;
}
-(UITextField*)wifiPwdTextField{
if (!_wifiPwdTextField) {
_wifiPwdTextField = InitObject(UITextField);
_wifiPwdTextField.placeholder = @"请输入WiFi密码";
_wifiPwdTextField.font = FontSize(14);
_wifiPwdTextField.keyboardType = UIKeyboardTypeAlphabet;
_wifiPwdTextField.delegate = self;
_wifiPwdTextField.backgroundColor = XWhite;
_wifiPwdTextField.secureTextEntry = YES;
_wifiPwdTextField.layer.masksToBounds = YES;
_wifiPwdTextField.layer.cornerRadius = kSizeFrom750(10);
_wifiPwdTextField.leftViewMode = UITextFieldViewModeAlways;
UIView *leftView = InitObject(UIView);
leftView.frame = RECT(0, 0, kSizeFrom750(90), kSizeFrom750(90));
UIImageView *leftImage = [[UIImageView alloc] init];
[leftView addSubview:leftImage];
[leftImage setImage:IMAGEBYENAME(@"icons_con_lock")];
[leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(leftView);
make.width.height.mas_equalTo(kSizeFrom750(60));
}];
_wifiPwdTextField.leftView = leftView;
}
return _wifiPwdTextField;
}
-(void)loadLayout{
[self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kSizeFrom750(88));
make.centerX.mas_equalTo(self.view);
}];
[self.subTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.titleL);
make.top.mas_equalTo(self.titleL.mas_bottom).offset(kSizeFrom750(10));
}];
[self.wifiNameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.subTitleL.mas_bottom).offset(kSizeFrom750(80));
make.centerX.mas_equalTo(self.subTitleL);
make.width.mas_equalTo(kSizeFrom750(690));
make.height.mas_equalTo(kSizeFrom750(90));
}];
[self.wifiPwdTextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.width.height.mas_equalTo(self.wifiNameTextField);
make.top.mas_equalTo(self.wifiNameTextField.mas_bottom).offset(kSizeFrom750(50));
}];
[self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.top.mas_equalTo(self.wifiPwdTextField.mas_bottom).offset(kSizeFrom750(100));
make.width.mas_equalTo(kSizeFrom750(400));
make.height.mas_equalTo(kSizeFrom750(55));
}];
[self addContentLabel];;
}
-(void)addContentLabel{
UILabel *preLabel;
NSArray *textArr = @[@"1.选择信号较强的2.4G WiFi,将设备和手机尽量靠近路由器,正确填写WiFi密码即可快速让设备联备;",@"2.设备暂不支持5G WiFi,若已连接,请切换2.4G WiFi;",@"3.路由器不能开启如AP隔离、防蹭网、WLAN助手等限制WiFi接入的选项;",@"4.设备暂不支持WAP/WPA2 企业级WiFi,若已连接,请切换其他WiFi。"];
for (int i=3; i>=0; i--) {
UILabel *label = InitObject(UILabel);
label.text = textArr[i];
label.textColor = RGB_92;
label.font = FontSize(12);
label.numberOfLines = 0;
[self.view addSubview:label];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kSizeFrom750(60));
make.right.mas_equalTo(-kSizeFrom750(60));
if (preLabel==nil) {
make.bottom.mas_equalTo(self.view).offset(-kSizeFrom750(30));
} else {
make.bottom.mas_equalTo(preLabel.mas_top).offset(-kSizeFrom750(30));
}
}];
preLabel = label;
}
}
//获取WiFi信息
- (id)getSSIDInfo
{
NSArray *ifs = (id)CFBridgingRelease(CNCopySupportedInterfaces());
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
id info = nil;
for (NSString *ifnam in ifs) {
info = (id)CFBridgingRelease(CNCopyCurrentNetworkInfo((CFStringRef)ifnam));
if (info && [info count]) {
break;
}
}
return info ;
}
#pragma mark --buttonClick
-(void)nextBtnClick:(UIButton *)sender{
ConAquarChooseWiFiVC *chooseVC = InitObject(ConAquarChooseWiFiVC);
chooseVC.wifiName = self.wifiNameTextField.text;
chooseVC.wifiPwd = self.wifiPwdTextField.text;
[self.navigationController pushViewController:chooseVC animated:YES];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
@@ -0,0 +1,21 @@
//
// ConnectingAquarVC.h
// Ifish
//
// Created by wbzhan on 2019/9/20.
// Copyright © 2019 lianlian. All rights reserved.
//
#import "BaseViewController.h"
NS_ASSUME_NONNULL_BEGIN
/**
水族箱设备连接中
*/
@interface ConnectingAquarVC : BaseViewController
Copy NSString *wifiName;//设备要连接的WiFi名称
Copy NSString *wifiPassword;//智能设备要连接的WiFi密码
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,91 @@
//
// ConnectingAquarVC.m
// Ifish
//
// Created by wbzhan on 2019/9/20.
// Copyright © 2019 lianlian. All rights reserved.
//
#import "ConnectingAquarVC.h"
#import "HKPieChartView.h"
#import "dataContorl.h"
#import<SystemConfiguration/CaptiveNetwork.h>
#import "IFishHotpotUDPHelper.h"
#import "ESPTouchResult.h"
#import "ESPTouchTask.h"
#import "IfishDataUnity.h"
#import <GWP2P/GWP2P.h>
@interface ConnectingAquarVC ()
Strong HKPieChartView *progressView;
Strong UILabel *titleL;
Strong ESPTouchTask* epTask;
Strong NSMutableString *trackString;
/**
设备返回的mac地址
*/
Copy NSString *macAddress;
/**
是否正在绑定设备
*/
Assign BOOL isBindingDevice;
Strong NSTimer *bindTimer;
Assign NSInteger retryTimes;
@end
@implementation ConnectingAquarVC
- (void)viewDidLoad {
[super viewDidLoad];
[self addTitleViewWithTitle:@"尝试与设备建立连接"];
[self.view addSubview:self.progressView];
[self.view addSubview:self.titleL];
[self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.progressView.mas_bottom).offset(kSizeFrom750(80));
make.centerX.mas_equalTo(self.view);
make.width.mas_equalTo(kSizeFrom750(700));
}];
[self.progressView updatePercent:99 animation:YES];
//AP模式配网
[[GWP2PDeviceLinker shareInstance] p2pAPLinkDeviceWithWiFiSSID:self.wifiName wifiPassword:self.wifiPassword devicePassword:@"123" deviceReceive:^(NSString *deviceId, BOOL isSupport) {
//
NSLog(@"设备%@收到WiFi,isSupport:%d",deviceId,isSupport);
} deviceLinkIn:^(NSDictionary *deviceDict) {
//成功
}];
// Do any additional setup after loading the view.
}
- (HKPieChartView *)progressView
{
if (!_progressView) {
_progressView = [[HKPieChartView alloc]initWithFrame:RECT((screen_width - 100)/2, 120, 100, 100)];
}
return _progressView;
}
- (UILabel *)titleL
{
if (!_titleL) {
_titleL = InitObject(UILabel);
_titleL.text = @"设备连接中\n尽量使您的路由器、手机和设备互相靠近";
_titleL.textAlignment = NSTextAlignmentCenter;
_titleL.font = FontSize(16);
_titleL.numberOfLines = 2;
_titleL.textColor = RGB_92;
}
return _titleL;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end