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

ViewController.m 9.9KB

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