10
10
import UIKit
11
11
12
12
open class Device {
13
- static fileprivate func getVersionCode( ) -> String {
13
+ /// Get Version Code of the device.
14
+ /// - Parameter detectSimulator: if true, reture the Version Code like real device. Otherwise return Simulator.
15
+ /// - Returns: Version Code
16
+ static fileprivate func getVersionCode( detectSimulator: Bool = false ) -> String {
17
+ #if targetEnvironment(simulator)
18
+ if detectSimulator {
19
+ return ProcessInfo ( ) . environment [ " SIMULATOR_MODEL_IDENTIFIER " ] !
20
+ }
21
+ #endif
22
+
14
23
var systemInfo = utsname ( )
15
24
uname ( & systemInfo)
16
25
@@ -133,8 +142,8 @@ open class Device {
133
142
}
134
143
}
135
144
136
- static fileprivate func getType( code: String ) -> Type {
137
- let versionCode = getVersionCode ( )
145
+ static fileprivate func getType( code: String , detectSimulator : Bool ) -> Type {
146
+ let versionCode = getVersionCode ( detectSimulator : detectSimulator )
138
147
139
148
if versionCode. contains ( " iPhone " ) {
140
149
return . iPhone
@@ -149,8 +158,8 @@ open class Device {
149
158
}
150
159
}
151
160
152
- static public func version( ) -> Version {
153
- return getVersion ( code: getVersionCode ( ) )
161
+ static public func version( detectSimulator : Bool = false ) -> Version {
162
+ return getVersion ( code: getVersionCode ( detectSimulator : detectSimulator ) )
154
163
}
155
164
156
165
static public func size( ) -> Size {
@@ -221,8 +230,8 @@ open class Device {
221
230
}
222
231
}
223
232
224
- static public func type( ) -> Type {
225
- return getType ( code: getVersionCode ( ) )
233
+ static public func type( detectSimulator : Bool = false ) -> Type {
234
+ return getType ( code: getVersionCode ( detectSimulator : detectSimulator ) , detectSimulator : detectSimulator )
226
235
}
227
236
228
237
@available ( * , deprecated, message: " use == operator instead " )
@@ -244,15 +253,11 @@ open class Device {
244
253
return UIScreen . main. scale > 1.0
245
254
}
246
255
247
- static public func isPad( ) -> Bool {
248
- return type ( ) == . iPad
249
- }
250
-
251
- static public func isPhone( ) -> Bool {
252
- return type ( ) == . iPhone
256
+ static public func isPad( detectSimulator: Bool = true ) -> Bool {
257
+ return type ( detectSimulator: detectSimulator) == . iPad
253
258
}
254
259
255
- static public func isPod( ) -> Bool {
260
+ static public func isPod( detectSimulator : Bool = true ) -> Bool {
256
261
return type ( ) == . iPod
257
262
}
258
263
@@ -265,7 +270,7 @@ open class Device {
265
270
// MARK: - Dynamic island
266
271
extension Device {
267
272
static public var hasDynamicIsland : Bool {
268
- switch version ( ) {
273
+ switch version ( detectSimulator : true ) {
269
274
case . iPhone14Pro,
270
275
. iPhone14Pro_Max,
271
276
. iPhone15,
0 commit comments