// // ViewController.m // healthRingDemo // // Created by 周鹏 on 2024/3/14. // #import "ViewController.h" #import "ELDeviceTypeCell.h" #import "ELDemoDeviceModel.h" #import "ELDemoScanVC.h" #import #import "RingTestDemoVC.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UITableView *tableView; @property (weak, nonatomic) IBOutlet UILabel *versionLabel; @property (nonatomic, strong) NSArray *deviceArray; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.title = [NSString stringWithFormat:@"%@", @"智能戒指蓝牙SDK"]; self.versionLabel.text = [NSString stringWithFormat:@"SDK ver: %@ \nDemo ver: %@", ELSmartRingManager.sdkVersion, self.class.appVersion]; self.deviceArray = @[ [ELDemoDeviceModel modelWithIndex:@"00" imageName:@"ailink_connected_ic" title:@"智能戒指 Test" subtitle:@"1.0" entryVCName:NSStringFromClass(RingTestDemoVC.class) cids:@[@(0x005D)]]]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.deviceArray.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 88; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ELDemoDeviceModel *device = self.deviceArray[indexPath.row]; ELDeviceTypeCell *cell = [ELDeviceTypeCell subsribeCell:tableView]; cell.indexLabel.text = device.index; cell.titleLabel.text = device.titleText; cell.subtitleLabel.text = device.subtitleText; cell.iconImageView.image = [UIImage imageNamed:device.imageName]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { ELDemoDeviceModel *device = self.deviceArray[indexPath.row]; if (device.newType) { ELDemoScanVC *vc = [[ELDemoScanVC alloc] init]; vc.cids = device.cids; vc.demoDeviceModel = device; // vc.modalPresentationStyle = UIModalPresentationFullScreen; [self.navigationController presentViewController:vc animated:YES completion:^{ NSLog(@""); }]; __weak typeof(self) weakSelf = self; vc.selectedBlock = ^(ELAILinkPeripheral * _Nonnull per) { UIViewController *vc = [[NSClassFromString(device.entryVCName) alloc] init]; vc.title = [NSString stringWithFormat:@"%@_%@", device.titleText, device.subtitleText]; [vc setValue:per forKey:@"per"]; [weakSelf.navigationController pushViewController:vc animated:YES]; }; } else { UIViewController *vc = [[NSClassFromString(device.entryVCName) alloc] init]; vc.title = [NSString stringWithFormat:@"%@_%@", device.titleText, device.subtitleText]; [self.navigationController pushViewController:vc animated:YES]; } } + (NSString *)appName { NSDictionary *dic = [[NSBundle mainBundle] infoDictionary]; NSString *appName = [dic objectForKey:@"CFBundleDisplayName"]; return appName; } + (NSString *)appVersion { NSDictionary *dic = [[NSBundle mainBundle] infoDictionary]; NSString * version = [dic objectForKey:@"CFBundleShortVersionString"]; return version; } @end