iOS AILinkBleSDK - 蓝牙SDK
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

BabyScaleViewController.m 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // BabyScaleViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by iot_user on 2020/4/7.
  6. // Copyright © 2020 IOT. All rights reserved.
  7. //
  8. #import "BabyScaleViewController.h"
  9. #import "Masonry.h"
  10. #import <AILinkBleSDK/ELBabyScaleBleManager.h>
  11. #import "BabyScaleConnectViewController.h"
  12. @interface BabyScaleViewController ()<UITableViewDelegate,UITableViewDataSource,BabyScaleBleDelegate>
  13. @property (nonatomic, strong) UITableView *tableView;
  14. @property (nonatomic, strong) NSArray<ELPeripheralModel *> *devices;
  15. @end
  16. @implementation BabyScaleViewController
  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. [ELBabyScaleBleManager shareManager].babyScaleDelegate = self;
  28. [[ELBabyScaleBleManager shareManager] startScan];
  29. }
  30. -(void)viewDidDisappear:(BOOL)animated{
  31. [super viewDidDisappear:animated];
  32. [[ELBabyScaleBleManager shareManager] stopScan];
  33. }
  34. #pragma mark ============ ELBluetoothManagerDelegate ==============
  35. -(void)babyScaleManagerUpdateState:(ELBluetoothState)state{
  36. NSLog(@"bluetoothManagerUpdateBleState = %ld",state);
  37. }
  38. -(void)babyScaleManagerScanDevices:(NSArray<ELPeripheralModel *> *)babyScaleDevices{
  39. self.devices = babyScaleDevices;
  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. BabyScaleConnectViewController *vc = [[BabyScaleConnectViewController 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