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:
- Use an API only available for iOS 15 e.g. UITabBar.scrollEdgeAppearance
- Use #available(iOS 15, *) as condition
- 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.