iOS AILinkBleSDK - 蓝牙SDK
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ViewController.m 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // ViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by iot_user on 2020/4/7.
  6. // Copyright © 2020 IOT. All rights reserved.
  7. //
  8. #import "ViewController.h"
  9. #import "Masonry.h"
  10. #import <AILinkBleSDK/ELAILinkBleManager.h>
  11. #import <AILinkBleSDK/ELBluetoothManager.h>
  12. #import "ELDemoDeviceModel.h"
  13. #import "ELDeviceTypeCell.h"
  14. #import "ELDemoScanVC.h"
  15. #import "AiLinkSuperViewController.h"
  16. #import "InheritScanViewController.h"
  17. #import "BabyScaleViewController.h"
  18. #import "BloodScanViewController.h"
  19. #import "HeightGuageScanViewController.h"
  20. #import "RemoteControlScanViewController.h"
  21. #import "ForeheadScanViewController.h"
  22. #import "ThermometerScanViewController.h"
  23. #import "WheelMonitorScanViewController.h"
  24. #import "BodyFatScaleScanViewController.h"
  25. #import "BroadcastScaleViewController.h"
  26. #import "EightScaleScanViewController.h"
  27. #import "ToothbrushScanViewController.h"
  28. #import "ELBfsWifiScanVC.h"
  29. #import "OximeterScanViewController.h"
  30. #import "BloodSugarScanViewController.h"
  31. #import "CoffeeScaleScanViewController.h"
  32. #import "FoodThermometerScanViewController.h"
  33. #import "BroadcastNutritionScaleViewController.h"
  34. #import "NutritionScaleScanViewController.h"
  35. #import "AiFreshNutritionScaleScanViewController.h"
  36. #import "FaceMaskScanViewController.h"
  37. #import "SkipScanViewController.h"
  38. #import "HeightBodyFatScaleVC.h"
  39. @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
  40. @property (nonatomic, strong) UITableView *tableView;
  41. @property (nonatomic, strong) NSArray<ELDemoDeviceModel *> *deviceArray;
  42. @end
  43. @implementation ViewController
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. self.title = [NSString stringWithFormat:@"%@(v%@)", [self.class appName],[ self.class appVersion]];
  47. self.deviceArray = @[
  48. [ELDemoDeviceModel modelWithIndex:@"-" imageName:@"ailink_connected_ic" title:@"Parse data yourself" subtitle:@"有AILink协议自己解析数据" entryVCName:NSStringFromClass(InheritScanViewController.class)],
  49. [ELDemoDeviceModel modelWithIndex:@"04" imageName:@"type_baby_scale_ic" title:@"Baby Scale" subtitle:@"婴儿秤" entryVCName:NSStringFromClass(BabyScaleViewController.class)],
  50. [ELDemoDeviceModel modelWithIndex:@"05" imageName:@"type_sphygmomanometer_ic" title:@"Sphygmomanometer" subtitle:@"血压计" entryVCName:NSStringFromClass(BloodScanViewController.class)],
  51. [ELDemoDeviceModel modelWithIndex:@"06" imageName:@"type_height_measuring_instrument" title:@"Height Guage" subtitle:@"身高仪" entryVCName:NSStringFromClass(HeightGuageScanViewController.class)],
  52. [ELDemoDeviceModel modelWithIndex:@"07" imageName:@"type_control_vision_ic" title:@"Remote Control" subtitle:@"遥控器" entryVCName:NSStringFromClass(RemoteControlScanViewController.class)],
  53. [ELDemoDeviceModel modelWithIndex:@"08" imageName:@"type_temperature_gun_ic" title:@"Forehead thermometer" subtitle:@"额温枪" entryVCName:NSStringFromClass(ForeheadScanViewController.class)],
  54. [ELDemoDeviceModel modelWithIndex:@"09" imageName:@"type_thermometer_ic" title:@"Digital thermometer" subtitle:@"温度计" entryVCName:NSStringFromClass(ThermometerScanViewController.class)],
  55. [ELDemoDeviceModel modelWithIndex:@"10" imageName:@"type_tpms_ic" title:@"TPMS" subtitle:@"胎压监测" entryVCName:NSStringFromClass(WheelMonitorScanViewController.class)],
  56. [ELDemoDeviceModel modelWithIndex:@"11" imageName:@"type_body_fat_ic" title:@"Bluetooth BodyfatScale" subtitle:@"体脂秤" entryVCName:NSStringFromClass(BodyFatScaleScanViewController.class)],
  57. [ELDemoDeviceModel modelWithIndex:@"12" imageName:@"type_body_fat_ic" title:@"Bluetooth BroadcastScale" subtitle:@"广播秤" entryVCName:NSStringFromClass(BroadcastScaleViewController.class)],
  58. [ELDemoDeviceModel modelWithIndex:@"13" imageName:@"8_electrode_measurement_type" title:@"Eight-electrode scale" subtitle:@"八电极体脂秤" entryVCName:NSStringFromClass(EightScaleScanViewController.class)],
  59. [ELDemoDeviceModel modelWithIndex:@"14" imageName:@"type_brush" title:@"wifi-ble toothbrush" subtitle:@"WiFi-ble牙刷" entryVCName:NSStringFromClass(ToothbrushScanViewController.class)],
  60. [ELDemoDeviceModel modelWithIndex:@"15" imageName:@"type_body_fat_ic" title:@"wifi-ble bodyfatScale" subtitle:@"WiFi-ble体脂秤" entryVCName:NSStringFromClass(ELBfsWifiScanVC.class)],
  61. [ELDemoDeviceModel modelWithIndex:@"16" imageName:@"oximeter_search_icon1" title:@"Bluetooth Oximeter" subtitle:@"血氧仪" entryVCName:NSStringFromClass(OximeterScanViewController.class)],
  62. [ELDemoDeviceModel modelWithIndex:@"17" imageName:@"type_blood_sugar" title:@"Bluetooth BloodGlucoseMeter" subtitle:@"血糖仪" entryVCName:NSStringFromClass(BloodSugarScanViewController.class)],
  63. [ELDemoDeviceModel modelWithIndex:@"18" imageName:@"type_coffee_scale_ic" title:@"CoffeeScale" subtitle:@"咖啡秤" entryVCName:NSStringFromClass(CoffeeScaleScanViewController.class)],
  64. [ELDemoDeviceModel modelWithIndex:@"19" imageName:@"foodtem_icon_100" title:@"FoodThermometer" subtitle:@"食物温度计" entryVCName:NSStringFromClass(FoodThermometerScanViewController.class)],
  65. [ELDemoDeviceModel modelWithIndex:@"20" imageName:@"ailink_nutrition_scale_scale_connect" title:@"BrodcastNutritionScale" subtitle:@"广播营养秤" entryVCName:NSStringFromClass(BroadcastNutritionScaleViewController.class)],
  66. [ELDemoDeviceModel modelWithIndex:@"21" imageName:@"ailink_nutrition_scale_scale_connect" title:@"NutritionScale" subtitle:@"连接营养秤" entryVCName:NSStringFromClass(NutritionScaleScanViewController.class)],
  67. [ELDemoDeviceModel modelWithIndex:@"22" imageName:@"ailink_nutrition_scale_scale_connect" title:@"AiFreshNutritionScale" subtitle:@"好营养营养秤" entryVCName:NSStringFromClass(AiFreshNutritionScaleScanViewController.class)],
  68. [ELDemoDeviceModel modelWithIndex:@"23" imageName:@"type_smart_mask" title:@"FaceMask" subtitle:@"智能口罩" entryVCName:NSStringFromClass(FaceMaskScanViewController.class)],
  69. [ELDemoDeviceModel modelWithIndex:@"24" imageName:@"ailink_smart_skip_rope_device_ic" title:@"SkippingRope" subtitle:@"跳绳" entryVCName:NSStringFromClass(SkipScanViewController.class)],
  70. [ELDemoDeviceModel modelWithIndex:@"25" imageName:@"height_body_fat_scale_type_ic" title:@"HeightBodyFatScale" subtitle:@"身高体脂秤" entryVCName:NSStringFromClass(HeightBodyFatScaleVC.class) cids:@[@(ELSupportDeviceTypeHeightBodyFatScale)]],
  71. ];
  72. [self.view addSubview:self.tableView];
  73. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.top.left.mas_equalTo(8);
  75. make.right.bottom.mas_equalTo(-8);
  76. }];
  77. }
  78. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  79. return self.deviceArray.count;
  80. }
  81. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  82. return 88;
  83. }
  84. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  85. ELDemoDeviceModel *model = self.deviceArray[indexPath.row];
  86. ELDeviceTypeCell *cell = [ELDeviceTypeCell subsribeCell:tableView];
  87. cell.indexLabel.text = model.index;
  88. cell.titleLabel.text = model.titleText;
  89. cell.subtitleLabel.text = model.subtitleText;
  90. cell.iconImageView.image = [UIImage imageNamed:model.imageName];
  91. return cell;
  92. }
  93. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  94. ELDemoDeviceModel *device = self.deviceArray[indexPath.row];
  95. if (device.newType) {
  96. ELDemoScanVC *vc = [[ELDemoScanVC alloc] init];
  97. vc.cids = @[@(ELSupportDeviceTypeHeightBodyFatScale)];
  98. [self.navigationController presentViewController:vc animated:YES completion:^{
  99. NSLog(@"");
  100. }];
  101. __weak typeof(self) weakSelf = self;
  102. vc.selectedBlock = ^(ELAILinkPeripheral * _Nonnull per) {
  103. UIViewController *vc = [[NSClassFromString(device.entryVCName) alloc] init];
  104. vc.title = [NSString stringWithFormat:@"%@_%@", device.titleText, device.subtitleText];
  105. [vc setValue:per forKey:@"per"];
  106. [weakSelf.navigationController pushViewController:vc animated:YES];
  107. };
  108. } else {
  109. UIViewController *vc = [[NSClassFromString(device.entryVCName) alloc] init];
  110. vc.title = [NSString stringWithFormat:@"%@_%@", device.titleText, device.subtitleText];
  111. [self.navigationController pushViewController:vc animated:YES];
  112. }
  113. }
  114. - (UITableView *)tableView {
  115. if (_tableView == nil) {
  116. _tableView = [[UITableView alloc] init];
  117. _tableView.delegate = self;
  118. _tableView.dataSource = self;
  119. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  120. }
  121. return _tableView;
  122. }
  123. + (NSString *)appName {
  124. NSDictionary *dic = [[NSBundle mainBundle] infoDictionary];
  125. NSString *appName = [dic objectForKey:@"CFBundleDisplayName"];
  126. return appName;
  127. }
  128. + (NSString *)appVersion {
  129. NSDictionary *dic = [[NSBundle mainBundle] infoDictionary];
  130. NSString * version = [dic objectForKey:@"CFBundleShortVersionString"];
  131. return version;
  132. }
  133. @end