DeviceKit icon indicating copy to clipboard operation
DeviceKit copied to clipboard

identify app running under macOS 13 Catalyst

Open polymerchm opened this issue 6 years ago • 7 comments

Self-explanatory

polymerchm avatar Oct 22 '19 05:10 polymerchm

You can do that in the following way:

#if targetEnvironment(macCatalyst)
    let catalyst = true
#else
    let catalyst = false
#endif

Or do you rather want a function like so?

Device.current.isMacCatalyst

Zandor300 avatar Oct 28 '19 10:10 Zandor300

Hi @Zandor300 Thanks for this awesome project!

As per above

Device.current.description returns Simulator (iOS) when running in a Mac Catalyst app.

gabors avatar Nov 07 '19 06:11 gabors

identifier return "x86_64" when using catalyst app

so


simulator(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))

return Simulator (iOS)


case mac must be added? The difficulty is to respond correctly to some device attribute that changed according to device or even worst, the window/scene size

maybe a case macCatalyst(mac) with mac an enum for all mac devices or a struct with mac definition like screen size etc...

phimage avatar Nov 07 '19 13:11 phimage

Identification of Mac models would be ideal but I’m not sure what’s the apple API for that. For starters the description should probably fall back to a string like Mac if running under catalyst.

gabors avatar Nov 07 '19 15:11 gabors

I make a PR for mac runtime and models https://github.com/devicekit/DeviceKit/pull/217

With some change I test it with mac catalyst inside an iOS app My method to get device model identifier work on catalyst (ie. getting model identifier using Darwin.sysct )

So S1 / we could add all mac models into enum devices S2 / or add a macCatalyst(MacModel) with MacModel a new enum available only with iOS runtimes, which contains the list of mac Models S3 / just add macCatalyst case without macModel but S2 is possible , so why do the least...

phimage avatar Nov 12 '19 10:11 phimage

@phimage I think we don't need a macCatalyst(macModel) enum since the code that references the Mac models, in this case, will only be ran under an iOS/Catalyst target.

In case the code is in a framework that supports both iOS/Catalyst and native macOS, that can be checked using the following code I've posted here before:

#if targetEnvironment(macCatalyst)
    let catalyst = true
#else
    let catalyst = false
#endif

Zandor300 avatar Nov 12 '19 10:11 Zandor300

Yes but we could also identify a device without using DeviceKit

First I thinks it is crappy to return Simulator (iOS) on mac Catalyst when using Device.current, just macCatalyst at least (today we could do Device.current.realDevice = .unknown("iOS"))

If we want to display the device name or we want to have a generic switch case code that rely on DeviceKit, making a special case each time using the #if targetEnvironment is annoying I prefer

#if os(iOS)
 switch Device.current.realDevice {
 case .iPhone11Pro: 
    ...
 case .macCatalyst:
    ...
}
#endif

and yes I use `#if targetEnvironment(macCatalyst)` in my current test code for mac catalyst and DeviceKit to get mac model identifier instead of current "x86_64" 

phimage avatar Nov 12 '19 11:11 phimage