How do you determine if your iOS app is running on MacOS?
Currently, I am using the following code:
var weHaveMac = false
if #available(iOS 14.0, *) {
if UIDevice.current.userInterfaceIdiom == .mac {
weHaveMac = true
print ("Mac?: \(weHaveMac), system?: \(UIDevice.current.userInterfaceIdiom)")
}
}
But, the UIDevice.current.userInterfaceIdiom == .Mac test always returns false.
I am using Xcode 12.2 Beta with MacOS 11.0.1 Beta.
Currently, I am using the following code:
var weHaveMac = false
if #available(iOS 14.0, *) {
if UIDevice.current.userInterfaceIdiom == .mac {
weHaveMac = true
print ("Mac?: \(weHaveMac), system?: \(UIDevice.current.userInterfaceIdiom)")
}
}
But, the UIDevice.current.userInterfaceIdiom == .Mac test always returns false.
I am using Xcode 12.2 Beta with MacOS 11.0.1 Beta.
userInterfaceIdiom only returns Mac when the app opts into using the Mac idiom as a Mac Catalyst app. This situation is discussed in Adapting iOS Code to Run in the macOS Environment.