iOS AILinkBleSDK - 蓝牙SDK
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CoffeeScaleScanViewController.m 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // CoffeeScaleScanViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by LarryZhang on 2021/12/13.
  6. // Copyright © 2021 IOT. All rights reserved.
  7. //
  8. #import "CoffeeScaleScanViewController.h"
  9. #import <AILinkBleSDK/ELCoffeeScaleBleManager.h>
  10. #import "Masonry.h"
  11. #import "CoffeeScaleConnectionViewController.h"
  12. @interface CoffeeScaleScanViewController () <UITableViewDelegate, UITableViewDataSource, CoffeeScaleBleDelegate>
  13. @property(nonatomic, strong) UITableView *tableView;
  14. @property(nonatomic, strong) NSArray<ELPeripheralModel *> *devices;
  15. @end
  16. @implementation CoffeeScaleScanViewController
  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. [[ELCoffeeScaleBleManager shareManager] startScan];
  27. [ELCoffeeScaleBleManager shareManager].coffeeScaleDelegate = self;
  28. }
  29. - (void)viewWillDisappear:(BOOL)animated {
  30. [[ELCoffeeScaleBleManager shareManager] stopScan];
  31. }
  32. #pragma mark - CoffeeScaleBleDelegate
  33. - (void)deviceBleReceiveState:(ELBluetoothState)state {
  34. NSLog(@"deviceBleReceiveState = %ld", state);
  35. }
  36. - (void)deviceBleReceiveDevices:(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.peripheral.name, 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. CoffeeScaleConnectionViewController *vc = [[CoffeeScaleConnectionViewController 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