热点连接流程修改

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,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