iOS AILinkBleSDK - 蓝牙SDK
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

HeightGuageScanViewController.m 3.0KB

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