JLChen
2021-02-03 4715e99a9be1c50d8ec31f594af9ebde18647c94
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
//
//  EZDeviceUpgradeViewController.m
//  EZOpenSDKDemo
//
//  Created by DeJohn Dong on 15/12/23.
//  Copyright © 2015年 Ezviz. All rights reserved.
//
 
#import "EZDeviceUpgradeViewController.h"
 
#import "EZDeviceUpgradeStatus.h"
#import "EZStorageInfo.h"
 
@interface EZDeviceUpgradeViewController ()
 
@property (nonatomic, weak) IBOutlet UITextView *upgradeTextView;
@property (nonatomic, weak) IBOutlet UIButton *upgradeButton;
@property (nonatomic, weak) IBOutlet UIProgressView *upgradeProgressView;
@property (nonatomic, weak) IBOutlet UILabel *upgradeLabel;
@property (nonatomic, strong) NSTimer *timer;
 
@end
 
@implementation EZDeviceUpgradeViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = NSLocalizedString(@"device_upgrade_title", @"设备升级");
    self.upgradeTextView.text = self.version.upgradeDesc;
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
- (void)viewWillDisappear:(BOOL)animated {
    if (_timer)
    {
        [_timer invalidate];
        _timer = nil;
    }
    [super viewWillDisappear:animated];
}
 
/*
#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.
}
*/
 
- (IBAction)upgradeDevice:(id)sender
{
    [EZOPENSDK upgradeDevice:self.deviceSerial completion:^(NSError *error) {
        if (!error)
        {
            //5s获取一次升级状态
            _timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(checkUpgradeStatus:) userInfo:nil repeats:YES];
            self.upgradeButton.hidden = YES;
            self.upgradeLabel.hidden = NO;
            self.upgradeProgressView.hidden = NO;
        }
    }];
}
 
- (void)checkUpgradeStatus:(NSTimer *)checkTimer
{
    [EZOPENSDK getDeviceUpgradeStatus:self.deviceSerial
                           completion:^(EZDeviceUpgradeStatus *status, NSError *error) {
                               NSLog(@"status = %@",status);
                               if(status.upgradeStatus == 2)
                               {
                                   self.upgradeLabel.text = NSLocalizedString(@"device_upgrade_success", @"升级成功");
                                   [self.upgradeProgressView setProgress:1.0 animated:YES];
                               }
                               else {
                                   self.upgradeLabel.text = NSLocalizedString(@"device_upgrading",@"正在升级中");
                                   [self.upgradeProgressView setProgress:status.upgradeProgress/100.0 animated:YES];
                               }
                           }];
}
 
 
@end