Can you check with @available if your iOS app is running on Mac?

I don't want the function to be included if the iOS app is running on a Mac. (Designed for iPad)

For example the sample code below

@available(iOS 13.4, *) func keyPressed(_ key: UIKey) { .. }

The keyPressed function is included when running in iOS or iPadOS. I would like to know if there is a way to prevent the keyPressed function from being included at launch time, even when running an iOS app as "Designed for iPad" on M1/M2 devices.

"targetEnvironment(macCatalyst)"

When this is called, false is unconditionally displayed, so the distinction cannot be made.

#if ProcessInfo().isiOSAppOnMac func keyPressed(_ key: UIKey) { .. } #endif

If you use the code above, ProcessInfo cannot be executed in RunTime, so false is output unconditionally.

So far I'm looking for a possible way, but there doesn't seem to be any possible way.

If anyone has solved this problem, please reply.

The exact same binary runs on the Mac as on the iOS device when you use the “Designed for iPad” feature, so there is no way to cause your function to not be included.

It is possible to do a runtime test. I forget exactly how, is it a property of UIDevice maybe? (edit: it’s the ProcessInfo thing you already know about.)

Is there some reason why a runtime test doesn’t work for you?

Can you check with @available if your iOS app is running on Mac?
 
 
Q