andrealufino/Deviice
Swift library to easily check the current device and some more info about it.
Version 3
⚠️Note that this version contains breaking changes, do not update before checking the new library!.⚠️
Version 3 has been rewritten with one purpose in mind: be simple. Simple to use and simple to update, as version 2 was offering some interesting structures, but was a pain to update. This version removed all classes except two, that are Device and Model, and introduced a json file to update when new devices are out. All the properties are now raw types, except for specificModel that is a computed property that returns a value of type Model. Cocoapods has been removed, following the pattern that most open source libraries are doing (for several years).
Usage
There is documentation for all the classes, methods and properties in the code. To give a general idea, this is how things work.
let device = Device.init() // This instantiate a `Device` object based on the current device.
print(device.marketingName) // This prints "iPhone 16 Pro" in case it is running on an iPhone 16 Pro
There is also the possibility to get the actual device being simulated on a Mac.
let device = Device.init()
print(device.marketingName) // This will print "Simulator".
print(device.simulatedDevice?.marketingName) // This will print "iPhone 16 Pro" in case you're simulating an iPhone 16 Pro.Add new devices
To add new devices there's just one thing that is a must: update the json. There's a nice to do step that is to update also the Model enumeration with the new model. This allows to have the property specificModel return a Model. Otherwise, it will return .notMapped and the value of the new model will be present in the specificModelRaw property as a String. So, to summarize, the steps are:
- Add the new device(s) to the json following the current structure.
- Add the new models to the
Modelenum assuring that they're named the same as thespecificModelRawkey in the json.
Requirements
This library works on iOS 15 or higher.
Installation
Deviice is available through Swift Package Manager.
Swift Package Manager
You can add this library via Swift Package Manager, using this url https://github.com/andrealufino/Deviice.
License
Deviice is available under the MIT license. See the LICENSE file for more info.
Package Metadata
Repository: andrealufino/Deviice
Stars: 78
Forks: 18
Open issues: 1
Default branch: develop
Primary language: swift
License: MIT
Topics: device, device-detection, device-detector, device-family, ios, ipad, iphone, model, swift, swift5, system, uidevice
README: README.md