6

I have added an iOS 15+/macCatalyst 15.0+ function to my app and now it is crashing when run on an M1 iMac through Mac Catalyst (Designed for iPad).

I have an availability check around my function however when run on my Mac (macOS 11.6), the code within the availability check still runs, and crashes.

if #available(iOS 15.0, macCatalyst 15.0, *) {
    dataSource.applySnapshotUsingReloadData(fullSnapshot, completion: nil)
} else {
    dataSource.apply(fullSnapshot, animatingDifferences: false)
}

I understand the Designed for iPad mac catalyst runs as iOS, and I can confirm it is running as iOS 14.7 using print(UIDevice.current.systemVersion) so why is it running code that is set to run on iOS 15+ only?

Am I doing my macCatalyst check right?

Darren
  • 10,182
  • 20
  • 95
  • 162
  • Maybe try `#if targetEnvironment(macCatalyst)` for Mac catalyst detection – pronebird Oct 04 '21 at 10:11
  • Code inside that check doesn't run! – Darren Oct 04 '21 at 10:13
  • It turns out, the `macCatalyst` check won't work because it's running as an `iOS` app and not full catalyst. However that doesn't explain why the `iOS 15` check doesn't work. – Darren Oct 04 '21 at 20:02
  • The environment check works fine when running on macOS 11.4. – pronebird Oct 05 '21 at 07:49
  • 1
    I am running an `iOS` app on an `M1` mac which apparently is different to running a full `macCatalyst` app. The app runs as if it's `iOS` so the `targetEnvironment` fails. But i've posted below the answer I got from Apple. – Darren Oct 05 '21 at 09:30

2 Answers2

7

It turns out this is a known issue and actually mentioned in the Xcode 13 release notes.

Availability checks in iPhone and iPad apps on a Mac with Apple silicon always return true. This causes iOS apps running in macOS 11 Big Sur to see iOS 15 APIs as available, resulting in crashes. This only affects apps available in the Mac App Store built with the “My Mac (Designed for iPhone)” or “My Mac (Designed for iPad)” run destination. It doesn’t affect Mac Catalyst apps. (83378814)

Workaround: Use the following code to check for iOS 15 availability:

if #available(iOS 15, *), ProcessInfo.processInfo.operatingSystemVersion.majorVersion >= 15 {
Darren
  • 10,182
  • 20
  • 95
  • 162
5

I need to check for this but I need to add functionality if running as an iOS app on the Mac and this seems to do the trick:

if ProcessInfo.processInfo.isiOSAppOnMac {
    // blah blah yada yada etc etc
}

There is also an isMacCatalystApp value as well.

cbiggin
  • 1,942
  • 1
  • 17
  • 18