This library provides run-time detection of the PPI (pixels per inch) resolution of the main display of an iOS device.
It is useful for applications that display content in true size, for example:
As Apple releases new iOS devices this library needs to be continously updated to add new devices to its built-in list. It cannot guarantee an accurate PPI value for new devices that it does not yet know, but in such cases it provides a "best guess" PPI based on heuristics (UIUserInterfaceIdiom
and UIScreen
values) and an error code which you can treat as a non-fatal error.
let ppi: Double = {
switch Ppi.get() {
case .success(let ppi):
return ppi
case .unknown(let bestGuessPpi, let error):
// A bestGuessPpi value is provided but may be incorrect
// Treat as a non-fatal error -- e.g. log to your backend and/or display a message
return bestGuessPpi
}
}()
iOS 8 or later.
Add a package dependency with this URL:
https://github.com/Clafou/DevicePpi
Alternatively, DevicePpi can be added to your project via CocoaPods.
pod 'DevicePpi'
Capacitor users can use this package on npm and GitHub
The list of devices and their PPI is updated as new models are announced. Currently, the following devices are included:
iPhone
iPod touch
iPad
Devices that are too old to support iOS 8 or later (this library's deployment target) are not included. These are: iPhone (original model), iPhone 3GS, iPhone 4, and the first, 2nd and 3rd generation of iPod touch.
Sébastien Molines
DevicePpi is available under the MIT license. See the LICENSE file for more info.
link |
Stars: 33 |
Last commit: 31 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics