iOS AILinkBleSDK - 蓝牙SDK
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

InheritScanViewController.m 2.9KB

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