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.

BodyFatScaleScanViewController.m 3.0KB

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