iOS AILinkBleSDK - 蓝牙SDK
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AiLinkSuperViewController.m 3.1KB

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