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
133
134
135
136
137
138
139
140
141
142
143
144
145
//
//  Copyright © 2018年 Zhejiang Dahua Technology Co.,Ltd. All rights reserved.
//    WIFI配置引导:手机音量设置检查
 
import UIKit
import AVFoundation
 
class DHPhoneVolumeCheckViewController: DHGuideBaseViewController {
 
    // 定时器
    fileprivate var timer: Timer?
    var btnTitleNum = 5
    var isPushed: Bool = false
    
    override func viewDidLoad() {
        super.viewDidLoad()
 
        // Do any additional setup after loading the view.
        adjustConstraint()
        let tipText = "common_next".lc_T
        let beginNum = "(5s)"
        let newTip = "\(tipText)\(beginNum)"
        guideView.nextButton.setTitle(newTip, for: .normal)
        startTimer()
        
 
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    private func adjustConstraint() {
        guideView.topImageView.contentMode = .scaleAspectFill
        guideView.updateTopImageViewConstraint(top: 0, width: view.bounds.width, maxHeight: 300)
    }
    
    private func pushToWifiConnectVC() {
        isPushed = true
        let controller = DHWifiConnectViewController.storyboardInstance()
        controller.showPlayAudio = DHAddDeviceManager.sharedInstance.isSupportSoundWave
        
        //【*】不支持声波
        //【*】支持声波的:国内,新旧声波提示(SMB只提示声波)
        //【*】支持声波的:海外提示
        if DHAddDeviceManager.sharedInstance.isSupportSoundWave == false {
            controller.descriptionContent = "add_device_keep_phone_close_to_device".lc_T
        } else {
            controller.descriptionContent = "add_device_adjust_phone_volume_to_hear_bugu".lc_T
        }
       
        self.navigationController?.pushViewController(controller, animated: true)
    }
 
    // MARK: - DHGuideBaseVCProtocol
    override func tipText() -> String? {
        if DHAddDeviceManager.sharedInstance.isSupportSoundWave {
            return "add_device_adjust_phone_volume".lc_T
        }
        
        return "add_device_keep_phone_close_to_device".lc_T
    }
    
    override func tipImageName() -> String? {
        if DHAddDeviceManager.sharedInstance.isSupportSoundWave {
            return "adddevice_netsetting_near"
        }
        return "adddevice_netsetting_closeto"
    }
    
    override func descriptionText() -> String? {
        //【*】不支持声波
        if DHAddDeviceManager.sharedInstance.isSupportSoundWave == false {
            return ""
        }
        
        //【*】提示声波
        //return "add_device_will_hear_volume".lc_T
        return "add_device_will_hear_bugu".lc_T
    }
    
    override func isCheckHidden() -> Bool {
        return true
    }
    
    override func doNext() {
        guard isPushed == false else {
            return
        }
        
        //支持声波配对才提示
        if DHAddDeviceManager.sharedInstance.isSupportSoundWave, checkPhoneVolueIsValid() == false {
            LCProgressHUD.showMsg("add_device_add_volume_tip".lc_T)
        }
        
        pushToWifiConnectVC()
    }
    
    override func rightActionType() -> [DHAddBaseRightAction] {
        var actions: [DHAddBaseRightAction] = [.restart]
        if DHAddDeviceManager.sharedInstance.supportConfigModes.contains(.wired) {
            actions.append(.switchToWired)
        }
        
        return actions
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        stopTimer()
        
    }
    func startTimer() {
        timer?.invalidate()
        timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.syncDownloadStatus), userInfo: nil, repeats: true)
    }
    
    func stopTimer() {
        timer?.invalidate()
    }
    
    @objc func syncDownloadStatus() {
        let next = "common_next".lc_T
        btnTitleNum -= 1
        let titleStr = "\(next)(\(btnTitleNum)s)"
        guideView.nextButton.setTitle(titleStr, for: .normal)
        if btnTitleNum == 0 {
            stopTimer()
            doNext()
        }
    }
 
    // MARK: - CheckVolume
    func checkPhoneVolueIsValid() -> Bool {
        var isValid = false
        let valume = AVAudioSession.sharedInstance().outputVolume
        print("🍎🍎🍎 \(NSStringFromClass(self.classForCoder))::Phone volume:\(valume)")
        if valume >= 0.8 {
            isValid = true
        }
        
        return isValid
    }
}