Tag Archives: UIDevice

How to test which iOS Hardware your app is running on

There are two ways to test which hardware your app is currently running on: compiler time and runtime. Both have their advantages.


Here’s how we can check both:

Compile Time Device Check

We can use the currentDevice method of our UIDevice class:

This will give you a string such as “iPhone”, “iPad” or “iPod Touch”.

Runtime Device Check

This is slightly more complex, but I’m sure you’ve heard of identifiers such as “iPhone6,1” or “iPad 3,3” – that’s Apple’s internal numbering system for iOS devices. With this check we can get very fine grained information about the hardware capabilities a device will have.

To use it, we need to first import the sysctrl framework into our app like so:

Then we can use some C methods that reads out this magic identifier. Here’s how:

First we grab the string of this magic identifier, then we compare it to a LONG list of possible values and extract the model number. The list above is not complete and it’s just meant for demo purposes. You get the idea.

The sysctrl functions are documented here:

Demo Project

I have a working demo project on GitHub which has a (relatively complete) list of current iOS device models. Check it out here:

Kudos to the following links that made this possible:

How to determine screen size in iOS

The UIDevice class can help us do that like so:

This will work fine in your View Controllers and App Delegate files.

I’ve got a full working demo project on GitHub: https://github.com/versluis/ScreenSize

Further Reading:

How to check which iOS version your device is running

We can check the UIDevice’s property systemVersion for this. Here’s a quick snippet that checks this, and conveniently checks the first number in the returned value. This should work until iOS 9…

I’ve created a demo project for this code on GitHub:

Inspired by this thread:

How to check if your app is running on an iPad or an iPhone

Here’s how we check that:

Alternatively you can check the same method for UIUserInterfaceIdiomPhone instead, which is returned when you’re on an iPhone or iPod touch.

How to check the battery level of your iOS device?

We can use the batteryLevel property of the UIDevice class for this. It will return a float:

If you’d like to print this in a UILabel you’ll have to convert it into a String Object like so:

For this to work battery monitoring needs to be enabled, perhaps in the viewDidLoad method. Otherwise the returned value will be -1.0: