Skip to content

Commit

Permalink
Add New Devices (#115)
Browse files Browse the repository at this point in the history
Checked and merged changes
  • Loading branch information
mlch911 committed Feb 25, 2023
1 parent 606b542 commit 2dba5f2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
8 changes: 6 additions & 2 deletions Source/Size.swift
Expand Up @@ -21,12 +21,16 @@ public enum Size: Int, Comparable {
case screen5_5Inch
/// iPhone X, Xs, 11 Pro
case screen5_8Inch
/// iPhone Xr, 11, 12, 12 Pro
/// iPhone Xr, 11, 12, 12 Pro, 13, 13 Pro, 14
case screen6_1Inch
/// iPhone 14 Pro
case screen6_1Inch_2
/// iPhone Xs Max, 11 Pro Max
case screen6_5Inch
/// iPhone 12 Pro Max
/// iPhone 12 Pro Max, 13 Pro Max, 14 Plus
case screen6_7Inch
/// iPhone 14 Pro Max
case screen6_7Inch_2
/// iPad Mini
case screen7_9Inch
/// iPad, iPad Pro (9.7-inch)
Expand Down
4 changes: 4 additions & 0 deletions Source/Version.swift
Expand Up @@ -41,6 +41,10 @@ public enum Version: String {
case iPhone13
case iPhone13Pro
case iPhone13Pro_Max
case iPhone14
case iPhone14Plus
case iPhone14Pro
case iPhone14Pro_Max

/*** iPad ***/
case iPad1
Expand Down
36 changes: 22 additions & 14 deletions Source/iOS/Device.swift
Expand Up @@ -13,12 +13,12 @@ open class Device {
static fileprivate func getVersionCode() -> String {
var systemInfo = utsname()
uname(&systemInfo)

let versionCode: String = String(validatingUTF8: NSString(bytes: &systemInfo.machine, length: Int(_SYS_NAMELEN), encoding: String.Encoding.ascii.rawValue)!.utf8String!)!

return versionCode
}

static fileprivate func getVersion(code: String) -> Version {
switch code {
/*** iPhone ***/
Expand Down Expand Up @@ -55,6 +55,10 @@ open class Device {
case "iPhone14,5": return .iPhone13
case "iPhone14,2": return .iPhone13Pro
case "iPhone14,3": return .iPhone13Pro_Max
case "iPhone14,7": return .iPhone14
case "iPhone14,8": return .iPhone14Plus
case "iPhone15,2": return .iPhone14Pro
case "iPhone15,3": return .iPhone14Pro_Max

/*** iPad ***/
case "iPad1,1", "iPad1,2": return .iPad1
Expand Down Expand Up @@ -104,10 +108,10 @@ open class Device {
default: return .unknown
}
}

static fileprivate func getType(code: String) -> Type {
let versionCode = getVersionCode()

if versionCode.contains("iPhone") {
return .iPhone
} else if versionCode.contains("iPad") {
Expand All @@ -120,16 +124,16 @@ open class Device {
return .unknown
}
}

static public func version() -> Version {
return getVersion(code: getVersionCode())
}

static public func size() -> Size {
let w: Double = Double(UIScreen.main.bounds.width)
let h: Double = Double(UIScreen.main.bounds.height)
let screenHeight: Double = max(w, h)

switch screenHeight {
case 240, 480:
return .screen3_5Inch
Expand All @@ -148,6 +152,8 @@ open class Device {
}
case 844:
return .screen6_1Inch
case 852:
return .screen6_1Inch_2
case 896:
switch version() {
case .iPhoneXS_Max, .iPhone11Pro_Max:
Expand All @@ -157,6 +163,8 @@ open class Device {
}
case 926:
return .screen6_7Inch
case 932:
return .screen6_7Inch_2
case 1024:
switch version() {
case .iPadMini, .iPadMini2, .iPadMini3, .iPadMini4, .iPadMini5:
Expand All @@ -180,7 +188,7 @@ open class Device {
return .unknownSize
}
}

static public func type() -> Type {
return getType(code: getVersionCode())
}
Expand All @@ -199,26 +207,26 @@ open class Device {
static public func isSmallerThanScreenSize(_ size: Size) -> Bool {
return size.rawValue > self.size().rawValue ? true : false;
}

static public func isRetina() -> Bool {
return UIScreen.main.scale > 1.0
}

static public func isPad() -> Bool {
return type() == .iPad
}

static public func isPhone() -> Bool {
return type() == .iPhone
}

static public func isPod() -> Bool {
return type() == .iPod
}

static public func isSimulator() -> Bool {
return type() == .simulator
}

}
#endif

0 comments on commit 2dba5f2

Please sign in to comment.