JLChen
2021-04-30 a5247b61d585627a1a7b1e1f35f34de9f0af9fba
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
//
//  Copyright © 2018年 Zhejiang Dahua Technology Co.,Ltd. All rights reserved.
//    对LCUserDeviceBindInfo的字段扩展
 
import Foundation
 
enum DHDeviceBindStatus {
    case unbind
    case bindBySelf
    case bindByOther
}
 
extension DHUserDeviceBindInfo {
    
    func dh_netConfigModes() -> [DHNetConfigMode] {
        var modes = [DHNetConfigMode]()
        if let configModes = self.wifiConfigMode, configModes.count > 0 {
            for mode in configModes.components(separatedBy: ",") {
                if mode.dh_caseInsensitiveContain(string: "SmartConfig") || mode.dh_caseInsensitiveContain(string: "SoundWave") {
                    if modes.contains(.wifi) == false { //防止重复添加
                        modes.append(.wifi)
                    }
                }
                
                if mode.dh_caseInsensitiveContain(string: "SoftAP") {
                    modes.append(.softAp)
                }
                
                if mode.dh_caseInsensitiveContain(string: "LAN") {
                    modes.append(.wired)
                }
                
                if mode.dh_caseInsensitiveContain(string: "SIMCard") {
                    modes.append(.simCard)
                }
                
                if mode.dh_caseInsensitiveSame(string: "Location") {
                    modes.append(.local)
                }
                
                if mode.dh_caseInsensitiveSame(string: "NBIOT") {
                    modes.append(.nbIoT)
                }
                
                if mode.dh_caseInsensitiveSame(string: "Bluetooth") {
                    modes.append(.ble)
                }
                
            }
        } else {
            modes.append(.wifi)
            modes.append(.wired)
            modes.append(.softAp)
        }
        
        if DHAddDeviceTest.openTest {
            modes.append(.nbIoT)
        }
    
        return modes
    }
    
    func dh_support5GWifi() -> Bool {
        if wifiTransferMode == nil {
            return false
        }
        return wifiTransferMode.dh_caseInsensitiveContain(string: "5Ghz")
    }
    
    func dh_isSupportSoundWave() -> Bool {
        //TEST::!!!
        if DHAddDeviceTest.openTest {
            return DHAddDeviceTest.testSoundWave
        }
        
        return wifiConfigMode != nil && wifiConfigMode.dh_caseInsensitiveContain(string: "SoundWave")
    }
    
    func dh_bindStatus() -> DHDeviceBindStatus {
        
        if bindStatus == nil || bindStatus.count == 0 || bindStatus.dh_caseInsensitiveContain(string: "unbind") {
            return .unbind
        }
        
        if bindStatus.dh_caseInsensitiveContain(string: "bindByMe") {
            return .bindBySelf
        }
        
        if bindStatus.dh_caseInsensitiveContain(string: "bindByOther") {
            return .bindByOther
        }
        
        return .unbind
    }
    
    func dh_isOnline() -> Bool {
        return status != nil && status.dh_caseInsensitiveSame(string: "online")
    }
    
    func dh_isExisted() -> Bool {
        return deviceExist != nil && deviceExist.dh_caseInsensitiveSame(string: "exist")
    }
    
    func dh_isAccesoryPart() -> Bool {
        return type != nil && type.dh_caseInsensitiveContain(string: "ap")
    }
    
    func dh_accessType() -> DHDeviceAccessType {
        if accessType == nil || accessType.count == 0 {
            return .paas
        }
        
        var type = DHDeviceAccessType.paas
        if accessType.dh_caseInsensitiveContain(string: "p2p") {
            type = .p2p
        } else if accessType.dh_caseInsensitiveContain(string: "easy4ip") {
            type = .easy4ip
        }
        
        return type
    }
}
 
// MARK: Extesion String
extension String {
    
    /// 忽略大小写的包含判断方法
    ///
    /// - Parameter string: 是否包含的字符串
    /// - Returns: YES/NO
    func dh_caseInsensitiveContain(string: String) -> Bool {
        let upperSelf = self.uppercased()
        let result = upperSelf.contains(string.uppercased())
        return result
    }
    
    /// 忽略大小写的判断是否相等
    ///
    /// - Parameter string: 是否包含的字符串
    /// - Returns: YES/NO
    func dh_caseInsensitiveSame(string: String?) -> Bool {
        if string == nil {
            return false
        }
        
        let upperSelf = self.uppercased()
        let result = upperSelf.caseInsensitiveCompare(string!.uppercased())
        return result == .orderedSame
    }
}