iOS AILinkBleSDK - 蓝牙SDK
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SkipScanViewController.m 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // FaceMaskScanViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by LarryZhang on 2021/12/13.
  6. // Copyright © 2021 IOT. All rights reserved.
  7. //
  8. #import "SkipScanViewController.h"
  9. #import <AILinkBleSDK/ELSkipBleManager.h>
  10. #import "Masonry.h"
  11. #import "SkipConnectionViewController.h"
  12. @interface SkipScanViewController () <UITableViewDelegate, UITableViewDataSource, ELSkipBleDelegate>
  13. @property(nonatomic, strong) UITableView *tableView;
  14. @property(nonatomic, strong) NSArray<ELPeripheralModel *> *devices;
  15. @end
  16. @implementation SkipScanViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Do any additional setup after loading the view.
  20. [self.view addSubview:self.tableView];
  21. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  22. make.top.left.right.bottom.mas_equalTo(0);
  23. }];
  24. }
  25. - (void)viewWillAppear:(BOOL)animated {
  26. [[ELSkipBleManager shareManager] startScan];
  27. [ELSkipBleManager shareManager].skipDelegate = self;
  28. }
  29. - (void)viewWillDisappear:(BOOL)animated {
  30. [[ELSkipBleManager shareManager] stopScan];
  31. }
  32. #pragma mark - BloodSugarBleDelegate
  33. - (void)skipManagerUpdateState:(ELBluetoothState)state {
  34. NSLog(@"---ble state:%ld",state);
  35. }
  36. - (void)skipManagerScanDevices:(NSArray<ELPeripheralModel *> *)scanDevices {
  37. self.devices = scanDevices;
  38. [self.tableView reloadData];
  39. }
  40. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  41. return self.devices.count;
  42. }
  43. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  44. return 60;
  45. }
  46. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  47. static NSString *cellId = @"cellid";
  48. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  49. if (!cell) {
  50. cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId];
  51. }
  52. ELPeripheralModel *p = self.devices[indexPath.row];
  53. cell.textLabel.text = [NSString stringWithFormat:@"Name:%@ Mac:%@ rssi:%ld \nCID:0x%04lX(%ld) VID:0x%04lX(%ld) PID:0x%04lX(%ld)", p.deviceName, p.macAddress, p.rssi, (unsigned long)p.cid, p.cid, (long)p.vid, p.vid, (long)p.pid, p.pid];
  54. cell.textLabel.numberOfLines = 2;
  55. cell.textLabel.textColor = [UIColor blackColor];
  56. return cell;
  57. }
  58. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  59. ELPeripheralModel *p = self.devices[indexPath.row];
  60. SkipConnectionViewController *vc = [[SkipConnectionViewController alloc] init];
  61. vc.p = p;
  62. [self.navigationController pushViewController:vc animated:YES];
  63. }
  64. - (UITableView *)tableView {
  65. if (_tableView == nil) {
  66. _tableView = [[UITableView alloc] init];
  67. _tableView.delegate = self;
  68. _tableView.dataSource = self;
  69. }
  70. return _tableView;
  71. }
  72. @end