Tips··SwiftiOS

How to detect iPadOS with Swift

iPadOS is an operating system based on iOS and this short post will show you how to detect iPadOS with Swift.

Aptabase Team @aptabase

The iPadOS was first introduced in 2019 and it is an operating system based on iOS. In some cases you might want to add some extra functionality to your app when running on iPadOS, or maybe you want to show a different UI. This short post will show you how to detect iPadOS with Swift.

  • Is there a #if os(ipados) like there is for iOS, tvOS and others? No, there is not.
  • Can I use something like #available(iPadOS 15, *)? No, this will not work.

So how do I detect iPadOS?

The UIUserInterfaceIdiom enum is what you want to use to detect the user interface idiom, which can be accessed via the userInterfaceIdiom property on the UIDevice class. The UIUserInterfaceIdiom enum has a pad option which you can use to detect if the device is an iPad.

if UIDevice.current.userInterfaceIdiom == .pad {
    print("This is an iPad!")
}

But wait, there is more! Just because it’s an iPad doesn’t mean it’s running iPadOS. Its only since the iOS 13 release that the iPad has been able to run iPadOS. So if you want to detect iPadOS specifically you can use the systemVersion property on the UIDevice class to check if the version is greater than or equal to 13.

if #available(iOS 13.0, *) {
    if UIDevice.current.userInterfaceIdiom == .pad {
        print("This is an iPad, and it's running iPadOS!")
    }
}

What about the UIDevice.current.systemName?

This property returns the name of the operating system. As of 2023, this property correctly returns iPadOS for iPad devices running iPadOS. But this was not always the case, up until iPadOS 15 this property would return iOS.

If you’re targeting iOS 15 or later you can use this property to detect iPadOS. But if you’re targeting iOS 14 or earlier you should use the method described above.

Analytics for Swift appsWithout compromising on privacy

Aptabase is a privacy-first analytics platform for Swift apps. Get insights into your app's usage in minutes.

Learn more
Aptabase Dashboard Screenshot

Want to learn more?

Where would you prefer to host your data?

European UnionGermanyUnited StatesVirginia

We typically advise selecting the region nearest to the majority of your users' locations. However, if your user base is global and dispersed, opt for the region that is geographically closest to your own location.