-1

I'm working on an app with Xcode 14.0 beta 3 (14A5270f). The target Supported Destinations are:

  • iPhone (iOS)
  • iPad (iOS)
  • Mac (macOS)

iOS Deployment Target is 16.0 macOS Deployment Target is 13.0

I'm looking for some way to detect which destination is running. I have a barcode scanning view that I only want to show on the iPhone or iPad destinations.

adamek
  • 2,324
  • 3
  • 24
  • 38
  • 2
    Does this documentation page give you any ideas? https://developer.apple.com/documentation/foundation/processinfo/3362531-ismaccatalystapp – matt Jul 16 '22 at 21:42

1 Answers1

3

Thanks to https://stackoverflow.com/users/341994/matt for the documentation pointer in the comments that got me going. Here's my final solution.

enum PlatformDestination: Int {
    case iPhone
    case iPad
    case iOSOnMac
    case MacCatalyst
    case Mac

    static func destination() -> PlatformDestination {
        #if os(iOS)
        switch UIDevice.current.userInterfaceIdiom {
        case .phone:
            return .iPhone
        case .pad:
            return .iPad
        case .carPlay:
            return .CarPlay
        case .tv:
            return .tvOS
        case .unspecified:
            break
        case .mac:
            return .iOSOnMac
        default:
            break
        }
        #endif
        if ProcessInfo().isMacCatalystApp {
            return .MacCatalyst
        } else {
            return .Mac
        }
    }
}
adamek
  • 2,324
  • 3
  • 24
  • 38