You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
220 lines
7.5 KiB
220 lines
7.5 KiB
// |
|
// DeviceLoseViewController.m |
|
// tongxin |
|
// |
|
// Created by ecell on 2022/11/3. |
|
// Copyright © 2022 xTT. All rights reserved. |
|
// |
|
|
|
#import "DeviceLoseViewController.h" |
|
#import "CommonTableView.h" |
|
#import "DeviceTableViewCell.h" |
|
#import "DeviceHeaderView.h" |
|
#import "TitleHeaderFooterView.h" |
|
#import "Bluetooth.h" |
|
#import <ReactiveObjC.h> |
|
|
|
|
|
@interface DeviceLoseViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate> |
|
|
|
@property (nonatomic ,strong) UITableView *loseTable; |
|
@property (nonatomic ,strong) NSMutableArray *bleArr; |
|
@property (nonatomic ,strong) DeviceHeaderView *headerView; |
|
@property (nonatomic ,strong) BLEModel *bleModel; |
|
|
|
@property (nonatomic ,weak) UIButton *sanBtn; |
|
|
|
|
|
@end |
|
|
|
static NSString *HeaderTitleIdentifier = @"TitleHeaderFooterView"; |
|
@implementation DeviceLoseViewController |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
// Do any additional setup after loading the view. |
|
self.zx_navTitle = @"蓝牙防丢"; |
|
self.emptyText = @"暂无设备"; |
|
|
|
NSString *switchNum = [[NSUserDefaults standardUserDefaults] objectForKey:@"WARNINGSWITCH"]; |
|
if (switchNum.length <= 0) |
|
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"WARNINGSWITCH"]; |
|
|
|
self.view.backgroundColor = RGB(245, 245, 245); |
|
UIButton *sanBtn = [UIButton new]; |
|
[sanBtn setTitle:@"开始扫描" forState:0]; |
|
sanBtn.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:Adapted(14)]; |
|
[sanBtn setTitleColor:[UIColor whiteColor] forState:0]; |
|
sanBtn.backgroundColor = mainColor; |
|
sanBtn.layer.cornerRadius = 3; |
|
sanBtn.layer.masksToBounds = YES; |
|
[sanBtn addTarget:self action:@selector(sanBle) forControlEvents:UIControlEventTouchUpInside]; |
|
self.sanBtn = sanBtn; |
|
[self.view addSubview:sanBtn]; |
|
[sanBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(self.view.mas_right).offset(-15); |
|
make.left.equalTo(self.view).offset(15); |
|
make.bottom.equalTo(self.view.mas_bottom).offset(iPhoneX ? -iPhoneX_TabbarSafeBottomMargin : -34); |
|
make.height.mas_equalTo(Adapted(48)); |
|
}]; |
|
|
|
MyUILabel *titleLabel = [UICommon ui_myLabel:CGRectZero lines:0 align:NSTextAlignmentLeft font:Font_(14) textColor:RGB(255, 182, 87) text:@"温馨提示:蓝牙防丢需要用户设置APP可以后台运行防止蓝牙后台断开,打开[后台弹出窗口][锁屏显示]权限接收防丢报警弹窗消息。" Radius:0]; |
|
titleLabel.backgroundColor = KKWhiteColorColor; |
|
[self.view addSubview:titleLabel]; |
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view); |
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight); |
|
make.height.mas_equalTo(70); |
|
}]; |
|
|
|
|
|
[self.view addSubview:self.loseTable]; |
|
[self.loseTable mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view); |
|
make.top.equalTo(titleLabel.mas_bottom).offset(1); |
|
make.bottom.equalTo(sanBtn.mas_top).offset(-10); |
|
}]; |
|
|
|
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"BLEUPDATA" object:nil] subscribeNext:^(NSNotification *notification) { |
|
self.bleArr = notification.object; |
|
[self.loseTable reloadData]; |
|
[self.sanBtn setTitle:@"开始扫描" forState:0]; |
|
[SVProgressHUD dismiss]; |
|
}]; |
|
|
|
|
|
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:BluetoothNotificationAtConnectSuccess object:nil] subscribeNext:^(NSNotification *notification) { |
|
self.bleModel = notification.object; |
|
self.headerView.bleModel = self.bleModel; |
|
[SVProgressHUD dismiss]; |
|
[self headerhi]; |
|
// for (BLEModel *model in self.bleArr) |
|
// { |
|
// if ([self.bleModel.MACString isEqualToString:model.MACString]) |
|
// { |
|
// [self.bleArr removeObject:model]; |
|
// [self.loseTable reloadData]; |
|
// return; |
|
// } |
|
// } |
|
}]; |
|
|
|
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:DISConnectedCurrenDevice object:nil] subscribeNext:^(NSNotification *notification) { |
|
self.bleModel = nil; |
|
[SVProgressHUD dismiss]; |
|
[self headerhi]; |
|
}]; |
|
|
|
if (Bluetooth.shareInstance.currenModel != nil) |
|
{ |
|
self.bleModel = Bluetooth.shareInstance.currenModel; |
|
if (!Bluetooth.shareInstance.isConnected) |
|
[Bluetooth.shareInstance connectPeripheralWithUUID]; |
|
self.headerView.bleModel = self.bleModel; |
|
[self headerhi]; |
|
} |
|
|
|
} |
|
|
|
- (UITableView *)loseTable |
|
{ |
|
if (!_loseTable) |
|
{ |
|
_loseTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; |
|
_loseTable.backgroundColor = [UIColor clearColor]; |
|
_loseTable.dataSource = self; |
|
_loseTable.delegate = self; |
|
_loseTable.showsVerticalScrollIndicator = NO; |
|
//_loseTable.separatorStyle = UITableViewCellSeparatorStyleNone; |
|
[_loseTable registerClass:DeviceTableViewCell.class forCellReuseIdentifier:NSStringFromClass(DeviceTableViewCell.class)]; |
|
[_loseTable registerClass:[TitleHeaderFooterView class] forHeaderFooterViewReuseIdentifier:HeaderTitleIdentifier]; |
|
_loseTable.rowHeight = Adapted(50); |
|
_loseTable.emptyDataSetSource = self; |
|
_loseTable.emptyDataSetDelegate = self; |
|
|
|
} |
|
return _loseTable; |
|
} |
|
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
DeviceTableViewCell *cell = [DeviceTableViewCell cellWithTableView:tableView indexPath:indexPath]; |
|
cell.bleModel = self.bleArr[indexPath.row]; |
|
return cell; |
|
} |
|
|
|
/// 返回row行数 |
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section |
|
{ |
|
return self.bleArr.count; |
|
} |
|
/// 返回 section个数 |
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView |
|
{ |
|
return 1; |
|
} |
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section |
|
{ |
|
return Adapted(45) ; |
|
} |
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section |
|
{ |
|
return 0.1; |
|
} |
|
|
|
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
|
|
} |
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section |
|
{ |
|
TitleHeaderFooterView *titleView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:HeaderTitleIdentifier]; |
|
titleView.backgroundColor = [UIColor clearColor]; |
|
return titleView; |
|
} |
|
|
|
|
|
|
|
- (DeviceHeaderView *)headerView |
|
{ |
|
if (!_headerView) |
|
{ |
|
_headerView = [[DeviceHeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, Adapted(113)+70)]; |
|
} |
|
return _headerView; |
|
} |
|
|
|
- (void)sanBle |
|
{ |
|
[SVProgressHUD showWithStatus:@"正在扫描..."]; |
|
[Bluetooth.shareInstance startScanBLE]; |
|
[self.sanBtn setTitle:@"正在扫描..." forState:0]; |
|
} |
|
|
|
- (void)headerhi |
|
{ |
|
self.loseTable.tableHeaderView = self.bleModel != nil ? self.headerView : nil; |
|
self.loseTable.tableHeaderView.height = self.bleModel != nil ? Adapted(113)+70 : 0; |
|
} |
|
|
|
|
|
- (void)viewDidDisappear:(BOOL)animated |
|
{ |
|
[super viewDidDisappear:animated]; |
|
//[Bluetooth.shareInstance cancelScan]; |
|
} |
|
|
|
/* |
|
#pragma mark - Navigation |
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation |
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { |
|
// Get the new view controller using [segue destinationViewController]. |
|
// Pass the selected object to the new view controller. |
|
} |
|
*/ |
|
|
|
@end
|
|
|