// // YXSetWifiViewController.m // Temperature // // Created by z on 2025/1/18. // #import "YXSetWifiViewController.h" #import "NSDictionary+WiFiInfo.h" #import #import "RDSBindDeviceVC.h" @interface YXSetWifiViewController () @property (weak, nonatomic) IBOutlet UIView *wifiNameView; @property (weak, nonatomic) IBOutlet UILabel *nameLabel; @property (weak, nonatomic) IBOutlet UIButton *wifiBtn; @property (weak, nonatomic) IBOutlet UIView *passwordView; @property (weak, nonatomic) IBOutlet UITextField *passwordTextField; @property (weak, nonatomic) IBOutlet UIButton *nextBtn; @property (strong, nonatomic) CLLocationManager *locationManager; @end @implementation YXSetWifiViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; [self createUI]; [self.locationManager startUpdatingLocation]; } -(void)createUI { self.wifiNameView.layer.cornerRadius = 20; self.wifiNameView.layer.borderWidth = 1.0; self.wifiNameView.layer.borderColor = [UIColor colorWithHexString:@"#C7C7C7"].CGColor; self.passwordView.layer.cornerRadius = 20; self.passwordView.layer.borderWidth = 1.0; self.passwordView.layer.borderColor = [UIColor colorWithHexString:@"#C7C7C7"].CGColor; [self.wifiBtn addTarget:self action:@selector(wifiBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [self.nextBtn addTarget:self action:@selector(nextBtnAction:) forControlEvents:UIControlEventTouchUpInside]; } -(void)wifiBtnAction:(UIButton *)btn { // 跳转系统设置 NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; } } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; } -(void)nextBtnAction:(UIButton *)btn { if ([NSDictionary rds_fetchSSIDInfo][@"SSID"] == nil) { [RDSHudShower showCenterToast:@"请手机先连接WiFi"]; return; } if (self.nameLabel.text.length == 0) { [RDSHudShower showCenterToast:@"请先连接WiFi"]; return; } if (self.passwordTextField.text.length == 0) { [RDSHudShower showCenterToast:@"请输入WiFi密码"]; return; } [self.view endEditing:YES]; RDSBindDeviceVC *vc = [[RDSBindDeviceVC alloc] init]; vc.deviceCode = self.deviceCode; vc.is_master = self.itemModel.is_master; vc.deviceName = self.deviceName; vc.wifiName = self.nameLabel.text; vc.pwd = self.passwordTextField.text; YXDeviceStepModel *model = _itemModel.steps.firstObject; vc.deviceTypeId = model.device_type_id; vc.home_id = self.home_id; vc.room_id = self.room_id; vc.type_id = self.type_id; vc.bluetooth = self.bluetooth; vc.need_device_code = self.need_device_code; if ([self.bluetooth integerValue] == 1 && [self.need_device_code integerValue] == 0) { vc.isYXJL = YES; vc.blueCode = self.blue_code; }else{ vc.isYXJL = NO; vc.blueCode = self.deviceCode; } [self pushViewController:vc animated:YES]; } -(CLLocationManager*)locationManager { if (!_locationManager) { _locationManager = [[CLLocationManager alloc] init]; _locationManager.delegate = self; _locationManager.distanceFilter = kCLLocationAccuracyThreeKilometers; [_locationManager requestWhenInUseAuthorization]; } return _locationManager; } -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { NSDictionary *wifiDic = [NSDictionary rds_fetchSSIDInfo]; NSString *ssid = [[wifiDic objectForKey:@"SSID"] lowercaseString]; self.nameLabel.text = ssid; } /* #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