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

ViewController.m 9.1KB

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