iOS AILinkBleSDK - 蓝牙SDK
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

OximeterScanViewController.m 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // OximeterScanViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by cliCk on 2021/1/28.
  6. // Copyright © 2021 IOT. All rights reserved.
  7. //
  8. #import "OximeterScanViewController.h"
  9. #import <AILinkBleSDK/ELOximeterBleManager.h>
  10. #import "Masonry.h"
  11. #import "OximeterConnectionViewController.h"
  12. @interface OximeterScanViewController () <UITableViewDelegate,UITableViewDataSource,ELOximeterBleDelegate>
  13. @property (nonatomic, strong) UITableView *tableView;
  14. @property (nonatomic, strong) NSArray<ELPeripheralModel *> *devices;
  15. @end
  16. @implementation OximeterScanViewController
  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. [[ELOximeterBleManager shareManager] startScan];
  27. [ELOximeterBleManager shareManager].oximeterBleDelegate = self;
  28. }
  29. - (void)viewWillDisappear:(BOOL)animated {
  30. [[ELOximeterBleManager shareManager] stopScan];
  31. }
  32. #pragma mark - ELOximeterBleDelegate
  33. - (void)oximeterManagerBleState:(ELBluetoothState)state {
  34. NSLog(@"bluetoothManagerUpdateBleState = %ld",state);
  35. }
  36. - (void)oximeterManagerScanDevices:(NSArray<ELPeripheralModel *> *)devices {
  37. self.devices = devices;
  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:%@\nCID:%ld---VID:%ld---PID:%ld",p.deviceName,p.macAddress,p.deviceType,p.vendorID,p.productID];
  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. OximeterConnectionViewController *vc = [[OximeterConnectionViewController 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