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.
170 lines
5.7 KiB
170 lines
5.7 KiB
// |
|
// DeviceLoseSetViewController.m |
|
// tongxin |
|
// |
|
// Created by ecell on 2022/11/11. |
|
// Copyright © 2022 xTT. All rights reserved. |
|
// |
|
|
|
#import "DeviceLoseSetViewController.h" |
|
#import <AudioToolbox/AudioToolbox.h> |
|
#import "Bluetooth.h" |
|
|
|
@interface DeviceLoseSetViewController () |
|
|
|
@property (nonatomic, strong)NSMutableArray *audioFileList; |
|
|
|
@end |
|
|
|
@implementation DeviceLoseSetViewController |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
// Do any additional setup after loading the view. |
|
self.title = @"防丢设置"; |
|
self.view.backgroundColor = RGB(245, 245, 245); |
|
|
|
UIImageView *leftImg = [UIImageView new]; |
|
leftImg.backgroundColor = mainColor; |
|
[self.view addSubview:leftImg]; |
|
[leftImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(self.view); |
|
make.top.equalTo(self.view).offset(15); |
|
make.size.mas_equalTo(CGSizeMake(3, 20)); |
|
}]; |
|
|
|
UILabel *titleLabel = [UILabel new]; |
|
titleLabel.textColor = KKGrey143; |
|
titleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:14]; |
|
titleLabel.text = @"基本设置"; |
|
[self.view addSubview:titleLabel]; |
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(leftImg.mas_right).offset(5); |
|
make.centerY.equalTo(leftImg); |
|
}]; |
|
|
|
for (int i = 0; i < 1; i++) |
|
{ |
|
UIView *bgView = [UIView new]; |
|
bgView.backgroundColor = [UIColor whiteColor]; |
|
bgView.layer.cornerRadius = 5; |
|
bgView.layer.masksToBounds = YES; |
|
[self.view addSubview:bgView]; |
|
[bgView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view).inset(15); |
|
make.top.equalTo(leftImg.mas_bottom).offset(15+i*15+i*Adapted(50)); |
|
make.height.mas_equalTo(Adapted(50)); |
|
}]; |
|
|
|
UIButton *btn = [UIButton new]; |
|
[btn setTitle:i == 0 ? @"蓝牙断开报警" : @"选择铃声" forState:0]; |
|
btn.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:Adapted(14)]; |
|
[btn setTitleColor:UIColor.blackColor forState:0]; |
|
btn.tag = i; |
|
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; |
|
[btn addTarget:self action:@selector(btnTouch:) forControlEvents:UIControlEventTouchUpInside]; |
|
[bgView addSubview:btn]; |
|
[btn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(bgView).inset(15); |
|
make.top.equalTo(bgView); |
|
make.height.mas_equalTo(Adapted(50)); |
|
}]; |
|
|
|
|
|
if (i == 0) |
|
{ |
|
NSString *switchNum = [[NSUserDefaults standardUserDefaults] objectForKey:@"WARNINGSWITCH"]; |
|
UISwitch *customSwitch = [[UISwitch alloc] init]; |
|
[customSwitch setOnTintColor:mainColor]; |
|
[customSwitch setOn:switchNum.boolValue]; |
|
[customSwitch addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged]; |
|
[bgView addSubview:customSwitch]; |
|
[customSwitch mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(bgView.mas_right).inset(10); |
|
make.centerY.equalTo(bgView); |
|
//make.size.mas_equalTo(CGSizeMake(Adapted(80), Adapted(40))); |
|
}]; |
|
} |
|
else |
|
{ |
|
|
|
} |
|
} |
|
|
|
// [self loadAudioFileList]; |
|
// NSLog(@"%@",self.audioFileList); |
|
|
|
} |
|
|
|
|
|
- (void)btnTouch:(UIButton *)btn |
|
{ |
|
|
|
} |
|
|
|
/** |
|
* 按钮切换事件监听回调方法 |
|
*/ |
|
- (void) switchChange:(UISwitch*)sw |
|
{ |
|
if (!Bluetooth.shareInstance.isConnected) |
|
{ |
|
[UICommon MessageErrorText:@"设备未连接!"]; |
|
return; |
|
} |
|
if(sw.on == YES) |
|
{ |
|
NSLog(@"开关切换为开"); |
|
[Bluetooth.shareInstance writeCheckBleWithBle:@"0x01"]; |
|
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"WARNINGSWITCH"]; |
|
|
|
} |
|
else if(sw.on == NO) |
|
{ |
|
NSLog(@"开关切换为关"); |
|
[Bluetooth.shareInstance writeCheckBleWithBle:@"0xFF"]; |
|
[[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:@"WARNINGSWITCH"]; |
|
} |
|
} |
|
|
|
|
|
- (void)loadAudioFileList{ |
|
self.audioFileList = [[NSMutableArray alloc] init]; |
|
|
|
NSFileManager *fileManager = [[NSFileManager alloc] init]; |
|
NSURL *directoryURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds"]; |
|
NSArray *keys = [NSArray arrayWithObject:NSURLIsDirectoryKey]; |
|
|
|
NSDirectoryEnumerator *enumerator = [fileManager |
|
enumeratorAtURL:directoryURL |
|
includingPropertiesForKeys:keys |
|
options:0 |
|
errorHandler:^(NSURL *url, NSError *error) { |
|
// Handle the error. |
|
// Return YES if the enumeration should continue after the error. |
|
return YES; |
|
}]; |
|
|
|
for (NSURL *url in enumerator) { |
|
NSError *error; |
|
NSNumber *isDirectory = nil; |
|
if (! [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error]) { |
|
// handle error |
|
} |
|
else if (! [isDirectory boolValue]) { |
|
[self.audioFileList addObject:url]; |
|
} |
|
} |
|
} |
|
|
|
/* |
|
#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
|
|
|