// // FirstViewController.m // Talk // // Created by xuzs on 22/10/11. // Copyright (c) 2022年 xuzs. All rights reserved. // #import "EquAdd.h" #import "HKHTextField.h" //#import "MainTabBar.h" #import "UI.h" #import "HttpManager.h" #import "Msg.h" #import "Pub.h" #import "sysInfo.h" #import "Sformat.h" #import "EquList.h" #import "Opendoor.h" #import "EquConfig.h" @interface EquAdd () @property (nonatomic, strong)UIView *rview; @property (nonatomic, strong)UILabel *equidLabel,*nameLabel; @property (nonatomic, strong)HKHTextField *equidTextField, *nameTextField; @property (nonatomic, strong)UIButton *addButton ,*selEquButton; @property (nonatomic, strong)UIAlertController *waiting; @property (nonatomic, strong) NSMutableArray *equArray; @end @implementation EquAdd - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //UIView *RootView = [[[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil] objectAtIndex:0]; //[self.title autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0,0,0,0)]; [self setupViews]; [self setUI]; if(self.equid == nil){ [self setupBle]; } //https://blog.csdn.net/liumude123/article/details/80579152 //[self.view setNeedsUpdateConstraints]; } - (void)updateViewConstraints { [super updateViewConstraints]; NSLog(@"updateViewConstraints"); [self setUI]; } - (void)setupViews { [self.view addSubview:self.rview]; [self.rview addSubview:self.equidLabel]; [self.rview addSubview:self.equidTextField]; [self.rview addSubview:self.nameLabel]; [self.rview addSubview:self.nameTextField]; [self.rview addSubview:self.addButton]; if(self.equid){ [self setNavTitle:@"命名设备"]; self.equidTextField.enabled = NO; self.equidTextField.text = self.equid; self.nameTextField.text = self.name; } else{ [self.rview addSubview:self.selEquButton]; self.equidTextField.enabled = NO; self.equidTextField.backgroundColor = [UIColor whiteColor]; [self setNavTitle:@"添加设备"]; [self.equidTextField resignFirstResponder]; //[self.equidTextField setUserInteractionEnabled:YES]; [self.selEquButton addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SelEqu)]]; [self.addButton setTitle:@"点击搜索门锁" forState:UIControlStateNormal]; } [self.addButton addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(AddEqu)]]; } - (void)setUI { [UI SetRView:self.rview Top:[[NSString alloc] initWithFormat:@"%f",[UI getStatuAndStatuHeight]+10] Right:@"20" Bottom:@"0" Left:@"20"]; [UI setFrameInView:self.equidLabel Width:@"70" Height:@"44" TranslateX:@"0" TranslateY:@"10" InView:nil Position:UITopLeft]; [UI setFrameInView:self.equidTextField Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"10" InView:nil Position:UITopRight]; [UI setFrameInView:self.nameLabel Width:@"70" Height:@"44" TranslateX:@"0" TranslateY:@"64" InView:nil Position:UITopLeft]; [UI setFrameInView:self.nameTextField Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"64" InView:nil Position:UITopRight]; [UI chgMargin:self.equidTextField Css:@"0 0 0 80"]; [UI chgMargin:self.nameTextField Css:@"0 0 0 80"]; [UI setFrameInView:self.addButton Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"140" InView:nil Position:UITopMid]; if(self.equid==nil){ [UI setFrameInView:self.selEquButton Width:@"100%" Height:@"44" TranslateX:@"0" TranslateY:@"10" InView:nil Position:UITopRight]; [UI chgMargin:self.selEquButton Css:@"0 0 0 80"]; } } - (void)setupBle{ _ble = [[CBCentralManager alloc] initWithDelegate:self queue:(nil)]; self.equArray = [[NSMutableArray alloc] init]; } #pragma mark-CBCentralManagerDelegate - (void)centralManagerDidUpdateState:(CBCentralManager *)central{ switch (central.state){ case CBCentralManagerStatePoweredOff:{ NSLog(@"蓝牙关闭"); [self alert:@"手机蓝牙未开启"]; } break; case CBCentralManagerStatePoweredOn:{ NSLog(@"蓝牙打开"); [self ScanEqu]; } break; default: break; } } - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{ if(peripheral.name==nil)return; if(![peripheral.name hasPrefix:@"T9A"])return; NSLog(@"发现蓝牙:%@,%@",peripheral,advertisementData); if(self.waiting){ [self.waiting dismissViewControllerAnimated:YES completion:nil]; self.waiting = nil; } if(self.device==nil){ self.device = peripheral; self.equidTextField.text = self.device.name; self.nameTextField.placeholder = self.device.name; [self.addButton setTitle:@"添加设备" forState:UIControlStateNormal]; } for(int i=0;i0 && index