iphoneDeviceModel lookup library
andreas.bergendal at gmail.com
Sun Oct 3 06:42:59 EDT 2021
This is for those of you who develop for iOS. We all know the challenge of getting the layout right for various iOS screens. ”The notch” (camera area at the top) is especially annoying, since there’s no easy way of knowing if the user’s device has one or not, and how many pixels it is (there are 4 variants!).
In LC 9.6.3 iphoneDeviceModel was introduced. Where machine() just returns ”iphone”, iphoneDeviceModel() returns e.g. ”iPhone10,6” (=iPhone X) or ”iPad13,7” (=iPad Pro 11 inch).
But the Dictionary entry on iphoneDeviceModel just links to a Wikipedia page listing mammoth tables of Apple device data. There is no way of knowing what ”iPhone10,6” means without a decent lookup table.
So, I’ve made one! And a library to use it with! And a demo stack to test it with!
It will check the device code of the current device, and return an array with values for:
- notch margin
- portrait bottom margin
- landscape bottom margin
- (device model name - in the rare case that you'd need it)
You use these for determining the safe area your UI elements can use, when rearranging them in response to the resizeStack message.
Or e.g. how much taller the Header bar widget needs to be on a ”notch” device in order to look good.
It’s all here and free to get, use and modify as you need:
The demo stack has the library in its stack script, and the full lookup array in a cProp, so that stack is all you need really.
Testing must be done by deploying to physical devices though, as iphoneDeviceModel() does not work in the iOS Simulator (or, it works, but just returns a code for the Simulator itself…).
Let me know if anything can be improved on (of course it can)! :)
The source for my data is this excellent website:
https://www.screensizes.app/ <https://www.screensizes.app/> which has comprehensive screen info on every existing iOS device since the first iPhone.
And this list which has the device codes interpreted:
More information about the use-livecode