Operating System availability checks have incorrect behavior on iOSAppOnMac: #available(iOS 15, *) is always true, ProcessInfo().isOperatingSystemAtLeast works as expected

Apple Silicon computers support running iOS apps. The property iOSAppOnMac of ProcessInfo is true for these apps. Checks like #available(iOS 15, *) are used to only access new APIs on operating systems that support them.

For iOSAppOnMac apps on Big Sur #available(iOS 15, *) evaluates to true despite ProcessInfo().isOperatingSystemAtLeast(.init(majorVersion: 15, minorVersion: 0, patchVersion: 0) evaluating to false. So without an additional check code like the example below crashes with an unrecognized selector exception.

Steps to reproduce:

  1. Use an API only available for iOS 15 e.g. UITabBar.scrollEdgeAppearance
  2. Use #available(iOS 15, *) as condition
  3. Code compiles, but crashes at runtime due to unrecognized selector on an iOSAppOnMac Big Sur device

Workaround:

Add ProcessInfo().isOperatingSystemAtLeast(.init(majorVersion: 15, minorVersion: 0, patchVersion: 0)) as condition.

Code sample from our app:

if
        #available(iOS 15, *),
ProcessInfo().isOperatingSystemAtLeast(.init(majorVersion: 15, minorVersion: 0, patchVersion: 0))

    {

        let tabBarScrollEdgeAppearance = tabBar.standardAppearance

        // ...

        tabBar.scrollEdgeAppearance = tabBarScrollEdgeAppearance

    }

Expectation:

I expect #available(iOS 15, *) to evaluate to false on iOSAppOnMac processes running Big Sur. Or in general, if the operating system major version returned by ProcessInfo is x then #available(iOS x+1, *) should be false.

Actual behavior:

#available(iOS x, *) always evaluates to true on iOSAppOnMac processes potentially causing crashing by using unavailable APIs.

It looks like you’re trying to report a bug; if so, please do that officially.

I’d appreciate you posting your bug number here, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Operating System availability checks have incorrect behavior on iOSAppOnMac: #available(iOS 15, *) is always true, ProcessInfo().isOperatingSystemAtLeast works as expected
 
 
Q