JLChen
2021-05-18 a869383e163a18cdedcf587383c1eca043129754
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
//
//  Copyright © 2018年 dahua. All rights reserved.
//    电源引导页:如果此时搜索到了设备,直接走有线添加
 
import UIKit
import CoreLocation
import LCBaseModule
 
class DHPowerGuideViewController: DHGuideBaseViewController {
    
    private lazy var locationManager: CLLocationManager = {
        let location = CLLocationManager()
        return location
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        adjustConstraint()
        
        addDeviceStartLog()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        /// 由于无线/有线添加过程中,会进行切换,不会重新创建controller,这里使用didAppear处理
 
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    private func adjustConstraint() {
        let width = min(view.bounds.width, 375)
        let height = 300 * width / 375
        guideView.updateTopImageViewConstraint(top: 0, width: width, maxHeight: height)
    }
    
    private func pushToInitializeSearchVC() {
        let controller = DHInitializeSearchViewController.storyboardInstance()
        self.navigationController?.pushViewController(controller, animated: true)
    }
    
    // MARK: DHAddBaseVCProtocol
    override func rightActionType() -> [DHAddBaseRightAction] {
        return  [.restart]
    }
    
    // MARK: DHGuideBaseVCProtocol
    override func tipText() -> String? {
        return "add_device_plug_power".lc_T
    }
    
    override func tipImageName() -> String? {
        return "adddevice_netsetting_power"
    }
    
    override func isCheckHidden() -> Bool {
        return true
    }
    
    override func isDetailHidden() -> Bool {
        return true
    }
    
    override func doNext() {
        //【*】iOS13兼容:点一步,如果是WIFI配网,则判断
        if #available(iOS 13.0, *), DHAddDeviceManager.sharedInstance.netConfigMode == .wifi {
            let status = CLLocationManager.authorizationStatus()
            if status == .notDetermined {
                //申请权限
                locationManager.requestWhenInUseAuthorization()
            } else if status == .denied {
                //被拒绝后,重新申请
                LCSetJurisdictionHelper.setJurisdictionAlertView("mobile_common_permission_apply".lc_T, message: "mobile_common_permission_explain_access_location_usage".lc_T)
            } else {
                //有位置访问权限,跳转下一步
                goNextStep()
            }
        } else {
            goNextStep()
        }
    }
    
    private func goNextStep() {
        //【*】局域网搜索到了设备:不需要初始化的,进入连接云平台;需要初始化的,进入初始化流程
        //【*】局域网搜索不到设备:进入配网流程
        if let device = DHAddDeviceManager.sharedInstance.getLocalDevice() {
            
            DHAddDeviceManager.sharedInstance.netConfigMode = .wired
            
            //【*】不需要初始化:支持sc码的设备、已经初始化的设备、没有初始化能力集的设备
            if DHAddDeviceManager.sharedInstance.isSupportSC ||
                device.deviceInitStatus == .init ||
                device.deviceInitStatus == .noAbility {
                self.basePushToConnectCloudVC(devicePassword: nil)
            } else {
                self.pushToInitializeSearchVC()
            }
        } else {
            let netConfigMode = DHAddDeviceManager.sharedInstance.netConfigMode
            if netConfigMode == .wired {
                let plugVc = DHPlugNetGuideViewController()
                self.navigationController?.pushViewController(plugVc, animated: true)
                
            } else if netConfigMode == .wifi {
                if DHNetWorkHelper.sharedInstance().emNetworkStatus == .reachableViaWiFi {
                    let passwordVc = DHWifiPasswordViewController.storyboardInstance()
                    let presenter = DHWifiPasswordPresenter(container: passwordVc)
                    passwordVc.setup(presenter: presenter)
                    self.navigationController?.pushViewController(passwordVc, animated: true)
                    
                } else {
                    let plugVc = DHWifiCheckViewController()
                    self.navigationController?.pushViewController(plugVc, animated: true)
                }
            }
        }
    }
    
    private func addDeviceStartLog() {
        let result = "{SN: \(DHAddDeviceManager.sharedInstance.deviceId),deviceModelName: \(DHAddDeviceManager.sharedInstance.deviceModel)}"
        let model = DHAddDeviceLogModel()
        model.bindDeviceType = StartAddType.NetworkConfig
        model.inputData = result
        DHAddDeviceLogManager.shareInstance.addDeviceStartLog(model: model)
    }
}