153 lines
5.3 KiB
Objective-C
153 lines
5.3 KiB
Objective-C
//
|
|
// 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(-30);
|
|
make.width.mas_equalTo(200);
|
|
make.height.mas_equalTo(30);
|
|
}];
|
|
|
|
[[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"];
|
|
//先判断之前的wifi名称是否和热点的wifi名称重复,如果冲突,则提示wifi名称错误
|
|
if ([wifiName isEqualToString:self.wifiName]) {
|
|
[self.view makeToast:@"请先连接设备热点"];
|
|
return;
|
|
}
|
|
if ([wifiName rangeOfString:@"ifish"].location!=NSNotFound) {
|
|
//wifi正确,则尝试连接设备
|
|
ConnectingAquarVC *connecting = InitObject(ConnectingAquarVC);
|
|
connecting.ssid = self.ssid;
|
|
connecting.bssid = self.bssid;
|
|
connecting.wifiName = self.wifiName;
|
|
connecting.wifiPassword = self.wifiPwd;
|
|
[self.navigationController pushViewController:connecting animated:YES];
|
|
}else{
|
|
[self.view makeToast:@"WiFi名称不匹配,请重试"];
|
|
}
|
|
}
|
|
- (NSDictionary *)getSSIDInfo
|
|
{
|
|
NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces());
|
|
NSDictionary *SSIDInfo;
|
|
for (NSString *interfaceName in interfaceNames) {
|
|
SSIDInfo = CFBridgingRelease(
|
|
CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName));
|
|
BOOL isNotEmpty = (SSIDInfo.count > 0);
|
|
if (isNotEmpty) {
|
|
break;
|
|
}
|
|
}
|
|
return SSIDInfo;
|
|
}
|
|
//即将进入前台
|
|
-(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
|