Skip to content

Commit

Permalink
[fix]: update device model reporting for iPhone, iPad, Apple Watch an…
Browse files Browse the repository at this point in the history
…d Apple TV devices
  • Loading branch information
kaushalkapasi committed Feb 12, 2024
1 parent 6bfbac5 commit a76de67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions DevCycle/Models/PlatformDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import IOKit

struct PlatformDetails {
#if os(iOS) || os(tvOS)
var deviceModel: String { UIDevice.current.model }
var deviceModel = getDeviceModel()
var systemVersion: String { UIDevice.current.systemVersion }
var systemName: String { UIDevice.current.systemName }
#elseif os(watchOS)
var deviceModel: String { WKInterfaceDevice.current().model }
var deviceModel = getDeviceModel()
var systemVersion: String { WKInterfaceDevice.current().systemVersion }
var systemName: String { WKInterfaceDevice.current().systemName }
#elseif os(macOS)
Expand Down Expand Up @@ -56,3 +56,12 @@ func getMacOSModelIdentifier() -> String {
}
}
#endif

#if os(iOS) || os(tvOS) || os(watchOS)
func getDeviceModel() -> String {
if let simulatorModelIdentifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] { return simulatorModelIdentifier }
var sysinfo = utsname()
uname(&sysinfo) // ignore return value
return String(bytes: Data(bytes: &sysinfo.machine, count: Int(_SYS_NAMELEN)), encoding: .ascii)!.trimmingCharacters(in: .controlCharacters)
}
#endif
4 changes: 2 additions & 2 deletions DevCycleTests/Models/DevCycleUserTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class DevCycleUserTest: XCTestCase {
#if os(tvOS)
XCTAssert(user.platform == "tvOS")
XCTAssertNotNil(user.platformVersion)
XCTAssert(user.deviceModel.contains("Apple TV"))
XCTAssert(user.deviceModel.contains("AppleTV"))
#elseif os(iOS)
XCTAssert(user.platform == "iOS" || user.platform == "iPadOS")
XCTAssertNotNil(user.platformVersion)
XCTAssert(user.deviceModel.contains("iPhone"))
XCTAssert(user.deviceModel.contains("iPhone") || user.deviceModel.contains("iPad"))
#elseif os(watchOS)
XCTAssert(user.platform == "watchOS")
XCTAssertNotNil(user.platformVersion)
Expand Down

0 comments on commit a76de67

Please sign in to comment.