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

FoodThermometerScanViewController.m 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // FoodThermometerScanViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by LarryZhang on 2021/12/13.
  6. // Copyright © 2021 IOT. All rights reserved.
  7. //
  8. #import "FoodThermometerScanViewController.h"
  9. #import <AILinkBleSDK/ELFoodThermometerBleManager.h>
  10. #import "Masonry.h"
  11. #import "FoodThermometerConnectionViewController.h"
  12. @interface FoodThermometerScanViewController () <UITableViewDelegate, UITableViewDataSource, FoodThermometerBleDelegate>
  13. @property(nonatomic, strong) UITableView *tableView;
  14. @property(nonatomic, strong) NSArray<ELPeripheralModel *> *devices;
  15. @end
  16. @implementation FoodThermometerScanViewController
  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. [[ELFoodThermometerBleManager shareManager] startScan];
  27. [ELFoodThermometerBleManager shareManager].foodThermometerBleDelegate = self;
  28. }
  29. - (void)viewWillDisappear:(BOOL)animated {
  30. [[ELFoodThermometerBleManager shareManager] stopScan];
  31. }
  32. #pragma mark - BloodSugarBleDelegate
  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.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. FoodThermometerConnectionViewController *vc = [[FoodThermometerConnectionViewController 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