
Translates Apple device codes into corresponding device names, aiding in identifying iOS devices. Offers easy integration with backend systems to decode device model codes.
iDevice is a simple no dependency Kotlin library for the JVM that translates Apple device codes into their corresponding device names.
It is used in the API Alerts platform to determine the model name of iOS devices to show in the users' device list.
Add the dependency to your Gradle toml file:
idevice = { module = "com.apialerts:idevice", version = "<version>" }or Groovy build.gradle file:
implementation 'com.apialerts:idevice:<version>'Ensure mavenCentral() is added to your repository list
Create an extension for UIDevice in your Swift iOS app to retrieve the device code:
// Swift
extension UIDevice {
func modelName() -> String {
var systemInfo = utsname()
uname(&systemInfo)
let mirror = Mirror(reflecting: systemInfo.machine)
let identifier = mirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
return identifier
}
}Use the extension to get the device model code:
// Swift
let model = UIDevice.current.modelName()Pass the device model code to your backend running a JVM API to decode it into a real device name:
// Kotlin
import com.apialerts.idevice.appleDeviceName
val model = appleDeviceName("<device code>")If the device code is in the supported devices lookup table, it returns the device name.
The repository needs to be updated when Apple releases new devices. Create a pull request with the new device code and model name to the lookup table in AppleDevices.kt.
This library is inspired by and credits DeviceKit.
iDevice is a simple no dependency Kotlin library for the JVM that translates Apple device codes into their corresponding device names.
It is used in the API Alerts platform to determine the model name of iOS devices to show in the users' device list.
Add the dependency to your Gradle toml file:
idevice = { module = "com.apialerts:idevice", version = "<version>" }or Groovy build.gradle file:
implementation 'com.apialerts:idevice:<version>'Ensure mavenCentral() is added to your repository list
Create an extension for UIDevice in your Swift iOS app to retrieve the device code:
// Swift
extension UIDevice {
func modelName() -> String {
var systemInfo = utsname()
uname(&systemInfo)
let mirror = Mirror(reflecting: systemInfo.machine)
let identifier = mirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
return identifier
}
}Use the extension to get the device model code:
// Swift
let model = UIDevice.current.modelName()Pass the device model code to your backend running a JVM API to decode it into a real device name:
// Kotlin
import com.apialerts.idevice.appleDeviceName
val model = appleDeviceName("<device code>")If the device code is in the supported devices lookup table, it returns the device name.
The repository needs to be updated when Apple releases new devices. Create a pull request with the new device code and model name to the lookup table in AppleDevices.kt.
This library is inspired by and credits DeviceKit.