123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //
- // RDSInputWiFiVC.m
- // Temperature
- //
- // Created by RD on 2022/11/21.
- //
- #import "RDSInputWiFiVC.h"
- #import "NSDictionary+WiFiInfo.h"
- #import "RDSBindDeviceVC.h"
- #import <CoreLocation/CoreLocation.h>
- @interface RDSInputWiFiVC ()<UITextFieldDelegate,CLLocationManagerDelegate>
- @property (weak, nonatomic) IBOutlet UITextField *wifiAccountTF;
- @property (weak, nonatomic) IBOutlet UITextField *wifiPwdTF;
- @property (weak, nonatomic) IBOutlet UIButton *nextBtn;
- @property (nonatomic, strong) CLLocationManager *locationManager;
- @end
- @implementation RDSInputWiFiVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
-
- [self.locationManager startUpdatingLocation];
-
- [self p_initUI];
-
- // APP由后台进入
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(p_reloadWiFi)name:UIApplicationWillEnterForegroundNotification object:nil];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
-
- [self p_reloadWiFi];
- }
- - (void) p_reloadWiFi{
-
- if(![self.wifiAccountTF.text isEqualToString:[NSDictionary rds_fetchSSIDInfo][@"SSID"]]){
- self.wifiAccountTF.text = [NSDictionary rds_fetchSSIDInfo][@"SSID"];
- self.wifiPwdTF.text = [kUserDefaults objectForKey:self.wifiAccountTF.text];
- }
-
- }
- #pragma mark - UI
- - (void)p_initUI {
-
- self.title = @"选择设备工作Wi-Fi";
- self.wifiAccountTF.delegate = self;
- self.wifiPwdTF.delegate = self;
-
- }
- - (IBAction)onChangeWifiClick {
-
- // 跳转系统设置
- NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
- if ([[UIApplication sharedApplication] canOpenURL:url]) {
- [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
- }
- }
- - (IBAction)onNextBtnClick:(UIButton *)sender {
-
- if ([NSDictionary rds_fetchSSIDInfo][@"SSID"] == nil) {
- [RDSHudShower showCenterToast:@"请把手机连接到WiFi"];
- return;
- }
- if (self.wifiAccountTF.text.length < 1) {
- [RDSHudShower showCenterToast:@"请输入WiFi信息"];
- return;
- }
-
- if (self.wifiPwdTF.text.length < 1) {
- [RDSHudShower showCenterToast:@"请输入WiFi信息"];
- return;
- }
-
- [self.view endEditing:YES];
-
- [kUserDefaults setObject:self.wifiPwdTF.text forKey:self.wifiAccountTF.text];
-
- RDSBindDeviceVC *vc = [[RDSBindDeviceVC alloc] init];
- vc.roomName = _roomName;
- vc.deviceID = _deviceID;
- vc.wifiName = self.wifiAccountTF.text;
- vc.pwd = self.wifiPwdTF.text;
- vc.deviceTypeModel = self.deviceTypeModel;
- [self pushViewController:vc animated:YES];
-
- }
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- [self.view endEditing:YES];
- }
- -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
- [self p_reloadWiFi];
- }
- -(CLLocationManager*)locationManager{
- if (!_locationManager) {
- _locationManager = [[CLLocationManager alloc] init];
- _locationManager.delegate = self;
- _locationManager.distanceFilter = kCLLocationAccuracyThreeKilometers;
- [_locationManager requestWhenInUseAuthorization];
- }
- return _locationManager;
- }
- @end
|