'Swift availability check for macCatalyst / iOS failing
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?
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
