YXSetWifiViewController.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // YXSetWifiViewController.m
  3. // Temperature
  4. //
  5. // Created by z on 2025/1/18.
  6. //
  7. #import "YXSetWifiViewController.h"
  8. #import "NSDictionary+WiFiInfo.h"
  9. #import <CoreLocation/CLLocationManager.h>
  10. #import "RDSBindDeviceVC.h"
  11. @interface YXSetWifiViewController ()<CLLocationManagerDelegate>
  12. @property (weak, nonatomic) IBOutlet UIView *wifiNameView;
  13. @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
  14. @property (weak, nonatomic) IBOutlet UIButton *wifiBtn;
  15. @property (weak, nonatomic) IBOutlet UIView *passwordView;
  16. @property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
  17. @property (weak, nonatomic) IBOutlet UIButton *nextBtn;
  18. @property (strong, nonatomic) CLLocationManager *locationManager;
  19. @end
  20. @implementation YXSetWifiViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.view.backgroundColor = [UIColor whiteColor];
  24. [self createUI];
  25. [self.locationManager startUpdatingLocation];
  26. }
  27. -(void)createUI
  28. {
  29. self.wifiNameView.layer.cornerRadius = 20;
  30. self.wifiNameView.layer.borderWidth = 1.0;
  31. self.wifiNameView.layer.borderColor = [UIColor colorWithHexString:@"#C7C7C7"].CGColor;
  32. self.passwordView.layer.cornerRadius = 20;
  33. self.passwordView.layer.borderWidth = 1.0;
  34. self.passwordView.layer.borderColor = [UIColor colorWithHexString:@"#C7C7C7"].CGColor;
  35. [self.wifiBtn addTarget:self action:@selector(wifiBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  36. [self.nextBtn addTarget:self action:@selector(nextBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  37. }
  38. -(void)wifiBtnAction:(UIButton *)btn
  39. {
  40. // 跳转系统设置
  41. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  42. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  43. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  44. }
  45. }
  46. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  47. [self.view endEditing:YES];
  48. }
  49. -(void)nextBtnAction:(UIButton *)btn
  50. {
  51. if ([NSDictionary rds_fetchSSIDInfo][@"SSID"] == nil) {
  52. [RDSHudShower showCenterToast:@"请手机先连接WiFi"];
  53. return;
  54. }
  55. if (self.nameLabel.text.length == 0) {
  56. [RDSHudShower showCenterToast:@"请先连接WiFi"];
  57. return;
  58. }
  59. if (self.passwordTextField.text.length == 0) {
  60. [RDSHudShower showCenterToast:@"请输入WiFi密码"];
  61. return;
  62. }
  63. [self.view endEditing:YES];
  64. RDSBindDeviceVC *vc = [[RDSBindDeviceVC alloc] init];
  65. vc.deviceCode = self.deviceCode;
  66. vc.is_master = self.itemModel.is_master;
  67. vc.deviceName = self.deviceName;
  68. vc.wifiName = self.nameLabel.text;
  69. vc.pwd = self.passwordTextField.text;
  70. YXDeviceStepModel *model = _itemModel.steps.firstObject;
  71. vc.deviceTypeId = model.device_type_id;
  72. vc.home_id = self.home_id;
  73. vc.room_id = self.room_id;
  74. vc.type_id = self.type_id;
  75. vc.bluetooth = self.bluetooth;
  76. vc.need_device_code = self.need_device_code;
  77. if ([self.bluetooth integerValue] == 1 && [self.need_device_code integerValue] == 0) {
  78. vc.isYXJL = YES;
  79. vc.blueCode = self.blue_code;
  80. }else{
  81. vc.isYXJL = NO;
  82. vc.blueCode = self.deviceCode;
  83. }
  84. [self pushViewController:vc animated:YES];
  85. }
  86. -(CLLocationManager*)locationManager
  87. {
  88. if (!_locationManager) {
  89. _locationManager = [[CLLocationManager alloc] init];
  90. _locationManager.delegate = self;
  91. _locationManager.distanceFilter = kCLLocationAccuracyThreeKilometers;
  92. [_locationManager requestWhenInUseAuthorization];
  93. }
  94. return _locationManager;
  95. }
  96. -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
  97. {
  98. NSDictionary *wifiDic = [NSDictionary rds_fetchSSIDInfo];
  99. NSString *ssid = [[wifiDic objectForKey:@"SSID"] lowercaseString];
  100. self.nameLabel.text = ssid;
  101. }
  102. /*
  103. #pragma mark - Navigation
  104. // In a storyboard-based application, you will often want to do a little preparation before navigation
  105. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  106. // Get the new view controller using [segue destinationViewController].
  107. // Pass the selected object to the new view controller.
  108. }
  109. */
  110. @end