How do the platforms differ in input, process model and capabilities, and which entitlements and APIs change per platform?

20.1.2 · L3 · Interview

Predict first

What do the UI idiom values read on tvOS?

import UIKit

print(UIUserInterfaceIdiom.tv.rawValue, UIUserInterfaceIdiom.phone.rawValue, UIUserInterfaceIdiom.pad.rawValue, UIUserInterfaceIdiom.carPlay.rawValue, UIUserInterfaceIdiom.mac.rawValue, UIUserInterfaceIdiom.vision.rawValue)
print(UIDevice.current.userInterfaceIdiom.rawValue)
  • 2 0 1 3 5 6, then 2
  • 0 1 2 3 4 5, then 0
  • 2 0 1 3 5 6, then 0

Mental model. Each platform is a different kind of venue: a theatre (iPhone) with a spotlight, a stage with many props (iPad and Mac), a lounge with a remote (TV), a pocket-sized stage that closes after thirty seconds (watch), and a stage that is the audience’s own room (visionOS). The same play needs a different staging in each.

Think of each platform as a different device contract. iPhone and iPad: touch (plus pointer, keyboard and Pencil on iPad), a foreground app with background modes, the full set of system frameworks. macOS: pointer and keyboard, many windows, a menu bar, long-running processes, a choice of sandbox (App Sandbox is required for the Mac App Store but optional outside it), and the file system and AppKit. tvOS: a remote and a focus engine, no touch and no pointer, a 10-foot display, media-first, and very limited background execution and local storage. watchOS: glances of seconds, the Digital Crown, tiny screens and batteries, health sensors, background work scheduled by the system, and an iPhone that may not be present. visionOS: windows, volumes and immersive spaces in the user’s room, gaze and hand input, RealityKit rendering. The UI idiom reflects this: UIUserInterfaceIdiom has phone (0), pad (1), tv (2), carPlay (3), mac (5, Catalyst) and vision (6), which on an Apple TV reports tv; use it (and size classes and the environment) to adapt, not device model strings.

The consequences for code. APIs are removed, not just discouraged: on tvOS UIImagePickerController and UIHoverGestureRecognizer are unavailable and digitalCrownRotation exists only on watchOS; FileDocument and DocumentGroup are iOS and macOS only; ImmersiveSpace and the volumetric window style exist only on visionOS; FileManager.homeDirectoryForCurrentUser is macOS only; isCompanionAppInstalled is a watchOS API and isWatchAppInstalled its iPhone counterpart. The compiler reports each as “unavailable in <platform>”, which is a useful way to discover the map. Capabilities and entitlements differ: App Groups and Keychain Sharing exist on all, but HealthKit, CarPlay, Network Extension, push (and its token types), background modes, App Sandbox, Hardened Runtime and notarization (macOS), Top Shelf and TV provider (tvOS), WatchKit app and extended runtime (watchOS) and the visionOS-specific entitlements are per platform, and each needs its own provisioning profile and App ID capabilities enabled. Distribution differs: separate store listings for tvOS and visionOS apps, watch apps bundled with an iPhone app or standalone, Mac apps through the Mac App Store or outside with notarization, and different review rules for each. Plan a matrix of what you build on each platform (a capability table: input, background, storage, networking, notifications, sign-in, in-app purchase) before writing shared code, since a shared interface that assumes a feature a platform lacks only moves the failure to run time.

The idiom constants are phone 0, pad 1, tv 2, carPlay 3, mac 5 and vision 6, and an Apple TV reports the tv idiom.

InputProcess modelDistinctive framework
iPhone / iPadtouch, plus pointer, keyboard and Pencil on iPadforeground app, background modesUIKit, SwiftUI, all system frameworks
macOSpointer, keyboard, many windowslong-running, sandbox optional outside the storeAppKit, menu bar, file system
tvOSSiri Remote and focus engine, controllersforeground media, almost no backgroundTVUIKit, TVServices, AVKit
watchOSDigital Crown, taps, always-on displayseconds foreground, scheduled refreshWatchKit, HealthKit workouts, complications
visionOSgaze and hand gestureswindows, volumes and immersive spacesRealityKit, ImmersiveSpace

Common traps

  • Assuming an API available on iOS exists everywhere. tvOS and watchOS remove many UIKit and SwiftUI APIs; the compiler says “unavailable in tvOS”.
  • Forgetting to enable a capability for each platform’s App ID. The build signs but the feature fails at run time.

They might follow up with

  • What does UIDevice.current.userInterfaceIdiom report on an Apple TV? .tv, raw value 2.
  • Which platforms need the App Sandbox decision? macOS: required for the Mac App Store, optional with notarized direct distribution.

Related questions

  • 20.1.1 How do you structure one codebase for several Apple platforms: shared cores, UI leaves, #if os, canImport and…
  • 20.4.2 What input and layout rules define a good tvOS interface: the Siri Remote, controllers, the 10-foot UI, and…
  • 20.6.1 What are windows, volumes and immersive spaces on visionOS, and how do you build for them with SwiftUI and…

← How do you structure one codebase for several Apple platforms: shared…   How do you run one shared core with several UI leaves on a single… →