DEV Community

Cover image for How to detect iPadOS with Swift
Guilherme Oenning
Guilherme Oenning

Posted on • Originally published at aptabase.com

How to detect iPadOS with Swift

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.

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!")
}
Enter fullscreen mode Exit fullscreen mode

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!")
    }
}
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)