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.
206 lines
6.7 KiB
206 lines
6.7 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> |
|
|
|
@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.title = @"设备防丢"; |
|
|
|
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)); |
|
}]; |
|
|
|
[self.view addSubview:self.loseTable]; |
|
[self.loseTable mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view); |
|
make.top.equalTo(self.view).offset(0); |
|
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]; |
|
[UICommon HidenLoading]; |
|
}]; |
|
|
|
|
|
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:BluetoothNotificationAtConnectSuccess object:nil] subscribeNext:^(NSNotification *notification) { |
|
self.bleModel = notification.object; |
|
self.headerView.bleModel = self.bleModel; |
|
[UICommon HidenLoading]; |
|
[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; |
|
[UICommon HidenLoading]; |
|
[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); |
|
|
|
} |
|
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 |
|
{ |
|
[UICommon MessageUpload:@"正在扫描..."]; |
|
[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
|
|
|