1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- //
- // FaceMaskScanViewController.m
- // AILinkBleSDKSourceCode
- //
- // Created by LarryZhang on 2021/12/13.
- // Copyright © 2021 IOT. All rights reserved.
- //
-
- #import "FaceMaskScanViewController.h"
- #import <AILinkBleSDK/ELFaceMaskBleManager.h>
- #import "Masonry.h"
- #import "FaceMaskConnectionViewController.h"
-
- @interface FaceMaskScanViewController () <UITableViewDelegate, UITableViewDataSource, FaceMaskBleDelegate>
-
- @property(nonatomic, strong) UITableView *tableView;
-
- @property(nonatomic, strong) NSArray<ELPeripheralModel *> *devices;
-
- @end
-
- @implementation FaceMaskScanViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.bottom.mas_equalTo(0);
- }];
- }
-
- - (void)viewWillAppear:(BOOL)animated {
- [[ELFaceMaskBleManager shareManager] startScan];
- [ELFaceMaskBleManager shareManager].faceMaskDelegate = self;
- }
-
- - (void)viewWillDisappear:(BOOL)animated {
- [[ELFaceMaskBleManager shareManager] stopScan];
- }
-
- #pragma mark - BloodSugarBleDelegate
-
- - (void)faceMaskBleReceiveState:(ELBluetoothState)state {
- NSLog(@"faceMaskBleReceiveState = %ld", state);
- }
-
- - (void)faceMaskBleReceiveDevices:(NSArray<ELPeripheralModel *> *)devices {
- self.devices = devices;
- [self.tableView reloadData];
- }
-
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.devices.count;
- }
-
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 60;
- }
-
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *cellId = @"cellid";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId];
- }
- ELPeripheralModel *p = self.devices[indexPath.row];
- cell.textLabel.text = [NSString stringWithFormat:@"Name:%@---Mac:%@\nCID:%ld---VID:%ld---PID:%ld", p.deviceName, p.macAddress, p.deviceType, p.vendorID, p.productID];
- cell.textLabel.numberOfLines = 2;
- cell.textLabel.textColor = [UIColor blackColor];
-
- return cell;
-
- }
-
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- ELPeripheralModel *p = self.devices[indexPath.row];
- FaceMaskConnectionViewController *vc = [[FaceMaskConnectionViewController alloc] init];
- vc.p = p;
- [self.navigationController pushViewController:vc animated:YES];
- }
-
- - (UITableView *)tableView {
- if (_tableView == nil) {
- _tableView = [[UITableView alloc] init];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- }
- return _tableView;
- }
-
- @end
|