// // ELDemoScanVC.m // AILinkBleSDK_Example // // Created by LarryZhang on 2022/12/12. // Copyright © 2022 zhengzida. All rights reserved. // #import "ELDemoScanVC.h" #import "ELDeviceScanCell.h" #import "ELDemoDeviceModel.h" #import #import @interface ELDemoScanVC () @property (weak, nonatomic) IBOutlet UILabel *bleStatusLabel; @property (weak, nonatomic) IBOutlet UITableView *tableView; @property (nonatomic, strong) ELSmartRingManager *smartRingManager; @property (nonatomic, strong) NSMutableArray *peripheralArray; @end @implementation ELDemoScanVC - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.bleStatusLabel.text = @""; [self initBle]; } - (void)dealloc { [self deinitBle]; } - (IBAction)closeAction:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; } #pragma mark - UITableViewDelegate, UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.peripheralArray.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 88; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ELDeviceScanCell *cell = [ELDeviceScanCell subsribeCell]; ELAILinkPeripheral *per = self.peripheralArray[indexPath.row]; cell.iconImageView.image = [UIImage imageNamed:self.demoDeviceModel.imageName]; cell.cidValueLabel.text = [NSString stringWithFormat:@"0x%02X", per.cid]; cell.vidValueLabel.text = [NSString stringWithFormat:@"0x%02X", per.vid]; cell.pidValueLabel.text = [NSString stringWithFormat:@"0x%02X", per.pid]; cell.macValueLabel.text = per.macAddressString; cell.rssiValueLabel.text = [NSString stringWithFormat:@"%@", per.RSSI]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { ELAILinkPeripheral *per = self.peripheralArray[indexPath.row]; if (self.selectedBlock) { self.selectedBlock(per); } [self dismissViewControllerAnimated:YES completion:nil]; } #pragma mark - ELAILinkBleManagerDelegate - (void)initBle { [ELSmartRingManager sharedManager].delegate = self; [self scanBle]; // self.bleManager = [[ELAILinkBleManager alloc] init]; // self.bleManager.ailinkDelegate = self; } - (void)scanBle { self.peripheralArray = [NSMutableArray array]; [[ELSmartRingManager sharedManager] scanFilterWithCidArray:self.cids]; } - (void)deinitBle { } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager managerDidUpdateState:(CBCentralManager *)central { NSLog(@"%s state:%@", __func__, @(central.state)); if (central.state == CBManagerStatePoweredOn) { [self scanBle]; } else if (central.state == CBManagerStatePoweredOff) { } } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager managerDidDiscoverPeripheral:(ELAILinkPeripheral *)peripheral { NSLog(@"managerDidDiscoverPeripheral cid:%02x vid:%02x pid:%02x mac:%@", peripheral.cid, peripheral.vid, peripheral.pid, peripheral.macAddressString); for (int i=0; i obj2.RSSI.integerValue) return NSOrderedAscending; return NSOrderedSame; }]; [self.tableView reloadData]; } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager ConnectState:(NELBleManagerConnectState)bleConnectState { } @end