萤石云 iOSSDK,移植跨平台相关工程
Davin
2024-06-07 4c1abca185a5727da6fb314a0cb4cd44bfe1b3bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
//
//  EZSettingViewController.m
//  EZOpenSDKDemo
//
//  Created by DeJohn Dong on 15/11/10.
//  Copyright © 2015年 Ezviz. All rights reserved.
//
 
#import "EZSettingViewController.h"
#import "DDKit.h"
#import "MBProgressHUD.h"
#import "Masonry.h"
 
#import "EZDeviceTableViewController.h"
#import "EZEditViewController.h"
#import <EZOpenSDKFramework/EZDeviceVersion.h>
#import "EZDeviceUpgradeViewController.h"
#import <EZOpenSDKFramework/EZStorageInfo.h>
#import "Toast+UIView.h"
#import "HDLEZDetectionTypeViewController.h"
 
//#import "EzvizDeviceManager.h"
 
@interface EZSettingViewController ()<UIActionSheetDelegate>
 
@property (nonatomic, strong) NSMutableArray *settingList;
@property (nonatomic, weak) IBOutlet UISwitch *videoSwitch;
@property (nonatomic, weak) IBOutlet UISwitch *actionSwitch;
@property (nonatomic, strong) UIImageView *actionRightArrow;
@property (weak, nonatomic) IBOutlet UISwitch *hdSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *privacyMaskSwitch;
@property (weak, nonatomic) IBOutlet UIImageView *rightArrowImg;
@property (nonatomic, weak) IBOutlet UILabel *nameLabel;
@property (nonatomic, weak) IBOutlet UILabel *serialLabel;
@property (nonatomic, weak) IBOutlet UILabel *currentVersionLabel;
@property (nonatomic, weak) IBOutlet UILabel *nVersionLabel;
@property (nonatomic, weak) IBOutlet UIImageView *updateImageView;
@property (nonatomic, strong) UIButton *deleteButton;
@property (nonatomic, strong) UIButton *privacyMaskButton;  // 隐私遮蔽执行过程提醒按钮
@property (nonatomic, strong) EZDeviceVersion *deviceVersion;
@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, assign) BOOL isCatEye;    // 是否为猫眼
@property (nonatomic, assign) BOOL privacyMasking;    // 隐私遮蔽设置中
 
@end
 
@implementation EZSettingViewController
 
- (void)dealloc
{
//    [[EzvizDeviceManager sharedManager] stopP2PHolePunching:_cameraInfo.cameraId];
}
 
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = NSLocalizedString(@"setting_device_set_title", @"设备设置");
    // 猫眼 CS-DH1, CS-DP1, CS-CV336, CS-CTQ1P
    // 门锁 DL30V,Y3000FV,DL20VC,DL31FS,DL30F,DL30,Y3000FVS,Y3000F
    self.isCatEye = NO;
    self.privacyMasking = NO;
    self.privacyMaskSwitch.on = NO;
    if ([self.deviceInfo.deviceType containsString:@"CS-DH1"] || [self.deviceInfo.deviceType containsString:@"CS-DP1"] || [self.deviceInfo.deviceType containsString:@"CS-CV336"] || [self.deviceInfo.deviceType containsString:@"CS-CTQ1P"]) {
        self.isCatEye = YES;
    }
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    if (!_settingList)
        _settingList = [NSMutableArray new];
    [_settingList addObject:@[NSLocalizedString(@"setting_device_name", @"设备名")]];
    [_settingList addObject:@[NSLocalizedString(@"setting_device_serial", @"序列号")]];
    [_settingList addObject:@[NSLocalizedString(@"setting_device_version", @"当前版本"),
                              NSLocalizedString(@"setting_device_new_version",@"最新版本")]];
    if (_deviceInfo.cameraNum == 0) {
        NSMutableString *str = [NSMutableString stringWithString:NSLocalizedString(@"setting_defense_status", @"防护状态:")];
        if (self.deviceInfo.defence == 0) {
            [str appendString:NSLocalizedString(@"setting_sleep_mode", @"睡眠模式")];
        } else if (self.deviceInfo.defence == 8) {
            [str appendString:NSLocalizedString(@"setting_home_mode", @"在家模式")];
        } else {
            [str appendString:NSLocalizedString(@"setting_out_mode", @"外出模式")];
        }
        [_settingList addObject:@[str]];
        [_settingList addObject:@[NSLocalizedString(@"setting_ignore_code", @"告警主机无视频图片加密功能")]];
        self.actionSwitch.hidden = YES;
        self.videoSwitch.hidden = YES;
    } else {
        [_settingList addObject:@[NSLocalizedString(@"setting_action_detect", @"活动检测提醒")]];
        [_settingList addObject:@[NSLocalizedString(@"setting_secure_code", @"视频图片加密")]];
        self.actionSwitch.on = self.deviceInfo.defence;
        self.videoSwitch.on = self.deviceInfo.isEncrypt;
    }
    [_settingList addObject:@[NSLocalizedString(@"setting_hardware_decoding", @"硬解码")]];
    if (!self.isCatEye) {
        [_settingList addObject:@[NSLocalizedString(@"setting_privacy_masking", @"隐私遮蔽")]];
        [_settingList addObject:@[NSLocalizedString(@"setting_sd_card_formatting", @"SD卡格式化")]];
    }
    [_settingList addObject:@[NSLocalizedString(@"delete", @"删除")]];
    
    self.serialLabel.text = self.deviceInfo.deviceSerial;
    
    self.updateImageView.hidden = YES;
    __weak __typeof(self)weakSelf = self;
    [EZOPENSDK getDeviceVersion:self.deviceInfo.deviceSerial
                     completion:^(EZDeviceVersion *version, NSError *error) {
        weakSelf.deviceVersion = version;
        weakSelf.currentVersionLabel.text = version.currentVersion;
        if(version.isNeedUpgrade) {
            weakSelf.nVersionLabel.text = version.latestVersion;
            weakSelf.updateImageView.hidden = NO;
        } else {
            weakSelf.updateImageView.hidden = YES;
            weakSelf.nVersionLabel.text = version.currentVersion;
        }
    }];
    [self.privacyMaskSwitch setOn:NO];
    [self getPrivacyMaskSwitchStatus];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.privacyMaskSwitch addSubview:self.privacyMaskButton];
    [self.privacyMaskButton addTarget:self action:@selector(privacyMaskingAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.privacyMaskButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
//    [[EzvizDeviceManager sharedManager] startP2PHolePunching:_cameraInfo.cameraId completion:^(BOOL result, NSError *error) {
//        NSLog(@"result = %d, error = %@", result, error);
//    }];
    
//    [EZOPENSDK getStorageStatus:self.cameraInfo.deviceSerial
//                     completion:^(NSArray *storageStatus, NSError *error) {
//                         NSLog(@"storageStatus = %@, error = %@", storageStatus, error);
//                         EZStorageInfo *info = storageStatus[0];
//                         [EZOPENSDK formatStorage:self.cameraInfo.deviceSerial
//                                     storageIndex:info.index
//                                       completion:^(NSError *error) {
//                                           NSLog(@"format command error = %@", error);
//                                           if (!error || error.code == 120016)
//                                           {
//                                               [self checkStorageStatus:nil];
//                                           }
//                                       }];
//                     }];
}
 
- (IBAction)checkStorageStatus:(id)sender
{
//    [EZOPENSDK getStorageStatus:self.cameraInfo.deviceSerial
//                     completion:^(NSArray *storageStatus, NSError *error) {
//                         NSLog(@"started format, storageStatus = %@, error = %@", storageStatus, error);
//                         if (!error)
//                         {
//                             //5s获取一次升级状态
//                             if (_timer)
//                             {
//                                 [_timer invalidate];
//                                 _timer = nil;
//                             }
//                             _timer = [NSTimer scheduledTimerWithTimeInterval:5.0
//                                                                       target:self
//                                                                     selector:@selector(checkStorageStatus:)
//                                                                     userInfo:nil
//                                                                      repeats:YES];
//                         }
//                     }];
}
 
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;//2021-02-01
    [self.tableView reloadData];
}
 
- (void)viewWillDisappear:(BOOL)animated {
    if (_timer) {
        [_timer invalidate];
        _timer = nil;
    }
//    self.navigationController.navigationBarHidden = YES;//2021-02-01 添加隐藏navigationBarHidden
    [super viewWillDisappear:animated];
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
- (void)getPrivacyMaskSwitchStatus {    // 获取镜头遮蔽开关状态
    __weak __typeof(self)weakSelf = self;
    [EZHttpUtil.sharedManager getCoverSwitchStatus:self.deviceInfo.deviceSerial completion:^(ResponseData * _Nonnull responseData) {
        if(responseData.success) {
            NSDictionary *dataDic = responseData.data;
            if (dataDic && [[dataDic allKeys] containsObject:@"enable"]) {  // 包含隐私遮蔽功能属性
                weakSelf.privacyMaskSwitch.enabled = YES;
                [weakSelf.privacyMaskSwitch setOn:[[dataDic objectForKey:@"enable"] boolValue]];
            } else {    // 不包含该功能
                weakSelf.privacyMaskSwitch.enabled = NO;
            }
        } else {
            weakSelf.privacyMaskSwitch.enabled = NO;
        }
    }];
}
 
#pragma mark - Table view data source
 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [self.settingList count];
}
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [[self.settingList dd_objectAtIndex:section] count];
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EZSettingCell" forIndexPath:indexPath];
    
    // Configure the cell...
    cell.backgroundColor = [UIColor whiteColor];
    cell.contentView.backgroundColor = [UIColor whiteColor];
    cell.textLabel.text = [[_settingList dd_objectAtIndex:indexPath.section] dd_objectAtIndex:indexPath.row];
    cell.textLabel.textColor = HDLEZHEXCOLOR(0x1B2D4D, 1.0);
    cell.textLabel.textAlignment = NSTextAlignmentLeft;
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.accessoryView = nil;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UIView *separatorLine = [[UIView alloc] init];
    separatorLine.hidden = YES; //   默认隐藏分割线
    [cell.contentView addSubview:separatorLine];
    separatorLine.backgroundColor = HDLEZHEXCOLOR(0xECEDEE, 1.);
    [separatorLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(cell.contentView.mas_left).offset(16.);
        make.bottom.mas_equalTo(cell.contentView.mas_bottom);
        make.right.mas_equalTo(cell.contentView.mas_right).offset(-16.);
        make.height.mas_equalTo(0.5);
    }];
    if (indexPath.section == 0)
    {
        [cell.contentView addSubview:self.nameLabel];
//        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        UIImageView *accessoryImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hdl_ez_list_next"]];
        accessoryImgView.frame = CGRectMake(0, 0, 16, 16);
        cell.accessoryView = accessoryImgView;
        [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(@140);
            make.trailing.mas_equalTo(cell.contentView.mas_trailing).offset(-10);
            make.centerY.mas_equalTo(cell.contentView.mas_centerY);
            make.height.mas_equalTo(@20);
        }];
        self.nameLabel.text = self.deviceInfo.deviceName;
    }
    else if (indexPath.section == 1)
    {
        [cell.contentView addSubview:self.serialLabel];
        [self.serialLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(@140);
            make.trailing.mas_equalTo(cell.contentView.mas_trailing).offset(-16);
            make.centerY.mas_equalTo(cell.contentView.mas_centerY);
            make.height.mas_equalTo(@20);
        }];
        self.serialLabel.text = self.deviceInfo.deviceSerial;
        separatorLine.hidden = NO;
    }
    else if (indexPath.section == 5)
    {
        [cell.contentView addSubview:self.hdSwitch];
        [self.hdSwitch mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(@(-16));
            make.centerY.mas_equalTo(cell.contentView.mas_centerY);
            make.width.mas_equalTo(@51);
            make.height.mas_equalTo(@31);
        }];
        BOOL hdStatus = [[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"EZVideoPlayHardDecodingStatus_%@", self.deviceInfo.deviceSerial]];
        self.hdSwitch.on = hdStatus;
        separatorLine.hidden = NO;
    }
    else if (indexPath.section == 6)
    {
        if (self.isCatEye) {    // 猫眼
            cell.backgroundColor = [UIColor clearColor];
            cell.contentView.backgroundColor = [UIColor clearColor];
            cell.textLabel.text = @"";
            [cell.contentView addSubview:self.deleteButton];
            [self.deleteButton addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside];
            [self.deleteButton mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.centerX.mas_equalTo(cell.contentView.mas_centerX);
                make.left.mas_equalTo(cell.contentView.mas_left).offset(77.);
                make.bottom.mas_equalTo(cell.contentView.mas_bottom);
                make.height.mas_equalTo(@44);
            }];
        } else {    // 摄像头
            [cell.contentView addSubview:self.privacyMaskSwitch];
            [self.privacyMaskSwitch mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.trailing.mas_equalTo(@(-16));
                make.centerY.mas_equalTo(cell.contentView.mas_centerY);
                make.width.mas_equalTo(@51);
                make.height.mas_equalTo(@31);
            }];
        }
    }
    else if (indexPath.section == 7)
    {
        [cell.contentView addSubview:self.rightArrowImg];
        [self.rightArrowImg mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(@(-16));
            make.centerY.mas_equalTo(cell.contentView.mas_centerY);
            make.width.mas_equalTo(@16);
            make.height.mas_equalTo(@16);
        }];
    }
    else if (indexPath.section == 8)
    {
        cell.backgroundColor = [UIColor clearColor];
        cell.contentView.backgroundColor = [UIColor clearColor];
        cell.textLabel.text = @"";
        [cell.contentView addSubview:self.deleteButton];
        [self.deleteButton addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside];
        [self.deleteButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(cell.contentView.mas_centerX);
            make.left.mas_equalTo(cell.contentView.mas_left).offset(77.);
            make.bottom.mas_equalTo(cell.contentView.mas_bottom);
            make.height.mas_equalTo(@44);
        }];
    }
    else if (indexPath.section == 3)
    {
//        [cell.contentView addSubview:self.actionSwitch];
//        [self.actionSwitch mas_remakeConstraints:^(MASConstraintMaker *make) {
//            make.trailing.mas_equalTo(@(-16));
//            make.centerY.mas_equalTo(cell.contentView.mas_centerY);
//            make.width.mas_equalTo(@51);
//            make.height.mas_equalTo(@31);
//        }];
        [cell.contentView addSubview:self.actionRightArrow];
        [self.actionRightArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(@(-16));
            make.centerY.mas_equalTo(cell.contentView.mas_centerY);
            make.width.mas_equalTo(@16);
            make.height.mas_equalTo(@16);
        }];
        separatorLine.hidden = NO;
    }
    else if (indexPath.section == 4)
    {
        [cell.contentView addSubview:self.videoSwitch];
        [self.videoSwitch mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(@(-16));
            make.centerY.mas_equalTo(cell.contentView.mas_centerY);
            make.width.mas_equalTo(@51);
            make.height.mas_equalTo(@31);
        }];
        separatorLine.hidden = NO;
    }
    else
    {
        if(indexPath.row == 0)
        {
            [cell.contentView addSubview:self.currentVersionLabel];
            [self.currentVersionLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.leading.mas_equalTo(@140);
                make.trailing.mas_equalTo(cell.contentView.mas_trailing).offset(-16);
                make.centerY.mas_equalTo(cell.contentView.mas_centerY);
                make.height.mas_equalTo(@20);
            }];
            separatorLine.hidden = NO;
        }
        else
        {
            [cell.contentView addSubview:self.nVersionLabel];
            [self.nVersionLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.leading.mas_equalTo(@140);
                make.trailing.mas_equalTo(cell.contentView.mas_trailing).offset(-16);
                make.centerY.mas_equalTo(cell.contentView.mas_centerY);
                make.height.mas_equalTo(@20);
            }];
            [cell.contentView addSubview:self.updateImageView];
            [self.updateImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.trailing.mas_equalTo(self.nVersionLabel.mas_leading).offset(5);
                make.centerY.mas_equalTo(self.nVersionLabel.mas_centerY);
            }];
        }
    }
    
    return cell;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return ((!self.isCatEye && indexPath.section == 8) || (self.isCatEye && indexPath.section == 6)) ? 92 : 50.;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.0001f;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return (section == 0 || section == 2 || (!self.isCatEye && section == 6)) ? 8.0f : 0.001f;
}
 
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return nil;
}
 
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return nil;
}
 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 8)
    {
//        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", @"取消") destructiveButtonTitle:NSLocalizedString(@"delete",@"删除") otherButtonTitles:nil];
//        [actionSheet showInView:self.view];
        
//        __weak __typeof(self)weakSelf = self;
//        UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//
//        [actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", @"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
//            [weakSelf dismissViewControllerAnimated:YES completion:^{
//            }];
//        }]];
//
//        [actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"delete",@"删除") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
//            [weakSelf deleteCurrentDevice];
//            [weakSelf dismissViewControllerAnimated:YES completion:^{
//            }];
//        }]];
//
//        [self presentViewController:actionSheet animated:YES completion:nil];
        
    }
//    else if (indexPath.section == 5)
//    {
//
//    }
    else if (indexPath.section == 0)
    {
        [self performSegueWithIdentifier:@"go2setDeviceName" sender:nil];
    }
    else if (indexPath.section == 2 && indexPath.row == 1 && self.updateImageView.hidden == NO)
    {
        [self performSegueWithIdentifier:@"go2Upgrade" sender:nil];
    }else if (indexPath.section == 3)
    {
        HDLEZDetectionTypeViewController *detectionTypeVC = [[HDLEZDetectionTypeViewController alloc] init];
        detectionTypeVC.deviceInfo = self.deviceInfo;
        
        [self.navigationController pushViewController:detectionTypeVC animated:YES];
    }
    else if (indexPath.section == 7)
    {
        UIAlertController *alert=[UIAlertController alertControllerWithTitle:HDLEZLocallizedString(@"alert_title") message:HDLEZLocallizedString(@"setting_formatting_alert_message") preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancle=[UIAlertAction actionWithTitle:HDLEZLocallizedString(@"device_temp_cancle") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        }];
        UIAlertAction *sure=[UIAlertAction actionWithTitle:HDLEZLocallizedString(@"device_temp_sure") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [EZOPENSDK formatStorage:self.deviceInfo.deviceSerial
                        storageIndex:0
                          completion:^(NSError *error) {
                if (error) {
                    NSLog(@"format command error = %@", error);
                    [UIView dd_showMessage:NSLocalizedString(@"setting_sd_card_fail", @"格式化失败,请重新再试")];
                } else {
                    NSLog(@"format command error = %@", error);
                    [UIView dd_showMessage:NSLocalizedString(@"setting_sd_card_success", @"格式化成功")];
                }
            }];
        }];
        [alert addAction:cancle];
        [alert addAction:sure];
        [self presentViewController:alert animated:YES completion:nil];
    }
}
 
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/
 
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/
 
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
 
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/
 
#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.
    if ([[segue destinationViewController] isKindOfClass:[EZEditViewController class]])
    {
        ((EZEditViewController *)[segue destinationViewController]).deviceInfo = self.deviceInfo;
    }
    else if ([[segue destinationViewController] isKindOfClass:[EZDeviceUpgradeViewController class]])
    {
        ((EZDeviceUpgradeViewController *)[segue destinationViewController]).deviceSerial = self.deviceInfo.deviceSerial;
        ((EZDeviceUpgradeViewController *)[segue destinationViewController]).version = self.deviceVersion;
    }
}
 
#pragma mark - UIActionSheetDelegate Methods
- (void)deleteCurrentDevice {
    __weak MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = NSLocalizedString(@"message_deleting", @"正在删除,请稍候...");
 
    [EZHttpUtil.sharedManager deleteDeviceByHDL:self.deviceInfo.deviceSerial completion:^(ResponseData *responseData) {
        [hud hide:YES];
        if(responseData.success) {
            NSArray *viewControllers = self.navigationController.viewControllers;
            for (UIViewController *vc in viewControllers)
            {
                if([vc isKindOfClass:[EZDeviceTableViewController class]])
                {
                    ((EZDeviceTableViewController *)vc).needRefresh = YES;
                    [self.navigationController popToViewController:vc animated:YES];
                    break;
                }
            }
        } else {
            NSString *mes = [NSString stringWithFormat:@"%@(%@)",NSLocalizedString(@"setting_opration_fail", @"操作失败"),responseData.code];
            [self.view makeToast:mes duration:2.0 position:@"center"];
        }
    }];
}
 
//- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
//{
//    if(buttonIndex == 0)
//    {
//        __weak MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//        hud.labelText = NSLocalizedString(@"message_deleting", @"正在删除,请稍候...");
////        [EZOPENSDK deleteDevice:self.deviceInfo.deviceSerial completion:^(NSError *error) {
////            if(!error)
////            {
////                [hud hide:YES];
////                NSArray *viewControllers = self.navigationController.viewControllers;
////                for (UIViewController *vc in viewControllers)
////                {
////                    if([vc isKindOfClass:[EZDeviceTableViewController class]])
////                    {
////                        ((EZDeviceTableViewController *)vc).needRefresh = YES;
////                        [self.navigationController popToViewController:vc animated:YES];
////                        break;
////                    }
////                }
////            }
////        }];
//
//        [EZHttpUtil.sharedManager deleteDeviceByHDL:self.deviceInfo.deviceSerial completion:^(ResponseData *responseData) {
//            [hud hide:YES];
//            if(responseData.success)
//            {
//                NSArray *viewControllers = self.navigationController.viewControllers;
//                for (UIViewController *vc in viewControllers)
//                {
//                    if([vc isKindOfClass:[EZDeviceTableViewController class]])
//                    {
//                        ((EZDeviceTableViewController *)vc).needRefresh = YES;
//                        [self.navigationController popToViewController:vc animated:YES];
//                        break;
//                    }
//                }
//            }else{
//                NSString *mes = [NSString stringWithFormat:@"%@(%@)",NSLocalizedString(@"setting_opration_fail", @"操作失败"),responseData.code];
//
//                [self.view makeToast:mes duration:2.0 position:@"center"];
//            }
//        }];
//
//
//    }
//}
 
#pragma mark - UIAlertViewDelegate Methods
 
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1)
    {
        NSString *smsCode = [alertView textFieldAtIndex:0].text;
        self.videoSwitch.enabled = NO;
        [EZOPENSDK setDeviceEncryptStatus:self.deviceInfo.deviceSerial
                               verifyCode:smsCode
                                  encrypt:NO
                               completion:^(NSError *error) {
                                    if (error)
                                    {
                                        [self.view makeToast:NSLocalizedString(@"setting_opration_fail", @"操作失败") duration:2.0 position:@"center"];
                                        [UIView dd_showMessage:error.localizedDescription];
                                        self.videoSwitch.on = YES;
                                    }
                                    else
                                    {
                                        [self.view makeToast:NSLocalizedString(@"setting_opration_success", @"操作成功") duration:2.0 position:@"center"];
                                        self.videoSwitch.on = NO;
                                        self.deviceInfo.isEncrypt = NO;
                                    }
                                   self.videoSwitch.enabled = YES;
                                }];
    } else {
        self.videoSwitch.on = YES;
    }
}
 
 
#pragma mark - Action Methods
 
- (IBAction)actionSwitchChanged:(id)sender
{
    __weak MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = NSLocalizedString(@"setting_switching", @"正在切换,请稍候...");
    /**
     *  注意;该demo只处理了IPC设备的布撤防,所有只有YES/NO,关于A系列设备请判断设备后修改枚举值再处理
     */
    [EZOPENSDK setDefence:self.actionSwitch.on
             deviceSerial:self.deviceInfo.deviceSerial
               completion:^(NSError *error) {
        
        [hud hide:YES];
        if (error) {
            [self.view makeToast:NSLocalizedString(@"setting_opration_fail", @"操作失败") duration:2.0 position:@"center"];
            self.actionSwitch.on = !self.actionSwitch.on;
        }
        else{
            self.deviceInfo.defence = self.actionSwitch.on;
        }
    }];
}
- (IBAction)HDChanged:(id)sender {
    
    UISwitch *hdSwitch = (UISwitch*)sender;
    BOOL status = hdSwitch.isOn;
    [[NSUserDefaults standardUserDefaults] setBool:status forKey:[NSString stringWithFormat:@"EZVideoPlayHardDecodingStatus_%@", self.deviceInfo.deviceSerial]];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
 
- (IBAction)privacyMasking:(id)sender {
    UISwitch *pmSwitch = (UISwitch*)sender;
    BOOL status = pmSwitch.isOn;
    
//    if (self.privacyMasking) {
//        self.privacyMaskSwitch.on = !status;
//        [UIView dd_showMessage:@"正在执行中,请稍后再试"];
//        return;
//    }
//
//    NSLog(@"#############设置状态:%@", status ? @"开启" : @"关闭");
    __weak __typeof(self)weakSelf = self;
    self.privacyMaskSwitch.enabled = NO;
    self.privacyMaskButton.hidden = NO;
    [self performSelector:@selector(delayPrivacyMasking) withObject:nil afterDelay:10.0];
    [EZHttpUtil.sharedManager coverSwitchStatus:self.deviceInfo.deviceSerial enable:(status ? 1 : 0) completion:^(ResponseData * _Nonnull responseData) {
        if(responseData.success) {
            NSLog(@"#############设置成功:%@", responseData.data);
        } else {
            NSLog(@"#############设置失败:%@", responseData.message);
            [UIView dd_showMessage:NSLocalizedString(@"setting_privacy_masking_fail", @"设置失败,请稍后再试")];
            [weakSelf.privacyMaskSwitch setOn:!status];
        }
        weakSelf.privacyMaskSwitch.enabled = YES;
    }];
}
 
- (void)privacyMaskingAction:(id)sender {
    [UIView dd_showMessage:NSLocalizedString(@"setting_privacy_masking_ing", @"正在执行中,请稍后再试")];
}
 
- (void)delayPrivacyMasking {
    self.privacyMaskButton.hidden = YES;
//    self.privacyMaskSwitch.enabled = YES;
}
 
- (IBAction)encryptChanged:(id)sender
{
    if(!self.videoSwitch.on)
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"setting_device_security_check", @"设备操作安全验证") message:NSLocalizedString(@"setting_input_code_plz",@"请输入该设备的设备验证码(设备标签上的6位字母)") delegate:self cancelButtonTitle:NSLocalizedString(@"cancel",@"取消") otherButtonTitles:NSLocalizedString(@"done",@"确定"), nil];
        alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
        [alertView show];
    }
    else
    {
        self.videoSwitch.enabled = NO;
        [EZOPENSDK setDeviceEncryptStatus:self.deviceInfo.deviceSerial
                               verifyCode:nil
                                  encrypt:YES
                               completion:^(NSError *error) {
                                    if (!error)
                                    {
                                        [self.view makeToast:NSLocalizedString(@"setting_opration_success", @"操作成功") duration:2.0 position:@"center"];
                                        self.videoSwitch.on = YES;
                                        self.deviceInfo.isEncrypt = YES;
                                    }
                                    else
                                    {
                                        [self.view makeToast:NSLocalizedString(@"setting_opration_fail", @"操作失败") duration:2.0 position:@"center"];
                                        [UIView dd_showMessage:error.localizedDescription];
                                    }
                                   self.videoSwitch.enabled = YES;
                                }];
    }
}
 
- (void)deleteAction {
    __weak __typeof(self)weakSelf = self;
    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    [actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", @"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        [weakSelf dismissViewControllerAnimated:YES completion:^{
        }];
    }]];
    
    [actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"delete",@"删除") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
        [weakSelf deleteCurrentDevice];
        [weakSelf dismissViewControllerAnimated:YES completion:^{
        }];
    }]];
    
    [self presentViewController:actionSheet animated:YES completion:nil];
}
 
#pragma mark - Getter
- (UIButton *)deleteButton {
    if (!_deleteButton) {
        _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _deleteButton.backgroundColor = [UIColor whiteColor];
        [_deleteButton setTitle:NSLocalizedString(@"delete", @"删除") forState:UIControlStateNormal];
        [_deleteButton setTitleColor:HDLEZHEXCOLOR(0xFF4747, 1.0) forState:UIControlStateNormal];
        _deleteButton.titleLabel.font = HDLEZ_Get_FontRegularWithSize(HDLEZ_FontSize_16);
        _deleteButton.layer.cornerRadius = 22.;
        _deleteButton.clipsToBounds = YES;
    }
    return _deleteButton;
}
 
- (UIButton *)privacyMaskButton {
    if (!_privacyMaskButton) {
        _privacyMaskButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _privacyMaskButton.backgroundColor = [UIColor clearColor];
        _privacyMaskButton.hidden = YES;
    }
    return _privacyMaskButton;
}
 
- (UIImageView *)actionRightArrow {
    if (!_actionRightArrow) {
        _actionRightArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hdl_ez_list_next"]];
        _actionRightArrow.contentMode = UIViewContentModeScaleAspectFill;
        _actionRightArrow.backgroundColor = UIColor.clearColor;
    }
    return _actionRightArrow;
}
 
@end