Supporting remote interactions in tvOS
At a glance
| Item | Summary |
|---|---|
| Purpose | Set up your app to support remote commands and events in a variety of scenarios by using the relevant approach. |
| App architecture | A Swift sample with the source-visible chain AppDelegate → CustomPlayerViewController → CustomPlayer → AVFoundation APIs. |
| Main patterns | View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks |
| Project style | 23 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: DispatchQueue.main.async; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: NotificationCenter. |
| Key frameworks/packages | UIKit, Foundation, MediaPlayer, AVKit, AVFoundation; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── DirectionalRemotes/
├── AppDelegate.swift
├── Custom Player/
│ ├── CustomPlayerViewController.swift
│ ├── CustomPlayer.swift
│ ├── CustomPlayerFeedbackView.swift
│ └── CustomPlayerView.swift
├── Remote Events/
│ ├── RemoteEventsViewController.swift
│ ├── RemoteEventsPlayer.swift
│ └── RemoteEventsView.swift
├── System Player/
│ └── SystemPlayerViewController.swift
├── Guide/
│ └── GuideViewController.swift
├── MenuViewController.swift
└── Shared/
└── RemoteCommand.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 6 project/configuration file(s) and 26 source declaration(s).
Overall architecture
flowchart LR
N1["AppDelegate"]
N2["CustomPlayerViewController"]
N3["CustomPlayer"]
N4["AVFoundation APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
DirectionalRemotes/AppDelegate.swift:12 — architecture anchor
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
var window: UIWindow?
// ...
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into AVFoundation.
Ownership and state
classDiagram
AppDelegate o-- UIWindow : window
CustomPlayerViewController *-- CustomPlayer : customPlayer
CustomPlayerViewController o-- View : view
RemoteEventsViewController *-- RemoteEventsPlayer : player
Ownership evidence
DirectionalRemotes/AppDelegate.swift:15 — stored dependency or nearest verified ownership anchor
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
var window: UIWindow?
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AppDelegate |
UIWindow (window) |
stores or receives | App/module collaborators |
CustomPlayerViewController |
CustomPlayer (customPlayer) |
creates and retains | Owning lexical scope |
CustomPlayerViewController |
View (view) |
stores or receives | App/module collaborators |
RemoteEventsViewController |
RemoteEventsPlayer (player) |
creates and retains | Owning lexical scope |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Queue scheduling | DispatchQueue.main.async |
The source addresses the main dispatch queue. | DirectionalRemotes/Custom Player/CustomPlayer.swift:212 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
DirectionalRemotes/Custom Player/CustomPlayer.swift:212 — representative execution boundary
DispatchQueue.main.async { [weak self] in
guard let self = self,
let currentItem = self.player.currentItem,
let currentProgram = self.currentProgram else { return }
// ...
}State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| State propagation | NotificationCenter |
NotificationCenter distributes named process-local events. | DirectionalRemotes/AppDelegate.swift:23 |
| Source import | UIKit |
The cited file imports this module; runtime use and architectural role are not inferred. | DirectionalRemotes/AppDelegate.swift:8 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | DirectionalRemotes/Custom Player/CustomPlayerUtilities.swift:9 |
| Source import | MediaPlayer |
The cited file imports this module; runtime use and architectural role are not inferred. | DirectionalRemotes/Custom Player/CustomPlayer.swift:8 |
| Source import | AVKit |
The cited file imports this module; runtime use and architectural role are not inferred. | DirectionalRemotes/Custom Player/CustomPlayerView.swift:8 |
| Source import | AVFoundation |
The cited file imports this module; runtime use and architectural role are not inferred. | DirectionalRemotes/AppDelegate.swift:10 |
| Source import | TVUIKit |
The cited file imports this module; runtime use and architectural role are not inferred. | DirectionalRemotes/Custom Player/CustomPlayerViewController.swift:8 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
DirectionalRemotes/Guide/GuideViewController.swift:14 — representative type boundary
protocol GuideReporting: AnyObject {
/// Called when a channel is selected in the guide view controller.
///
/// - Parameter channelId: The ID of the selected channel.
func selectedChannelId(_ channelId: Int)
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AppDelegate |
Receives callback-driven events | UIResponder, UIApplicationDelegate |
CustomPlayerViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
RemoteEventsViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
SystemPlayerViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
GuideViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
CustomPlayer |
Owns media or timeline playback | Concrete collaborators/imported frameworks |
RemoteEventsPlayer |
Owns media or timeline playback | Concrete collaborators/imported frameworks |
CustomPlayerFeedbackView |
User-interface presentation and input forwarding | UIView |
CustomPlayerView |
User-interface presentation and input forwarding | UIView |
MenuViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
The source explicitly defines local protocol relationships: CustomPlayerViewController → CustomPlayerReporting, MenuViewController → GuideReporting, RemoteEventsViewController → RemoteEventsPlayerReporting.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
playerState (DirectionalRemotes/Custom Player/CustomPlayer.swift:27) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
rateObserver (DirectionalRemotes/Custom Player/CustomPlayer.swift:34) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
statusObserver (DirectionalRemotes/Custom Player/CustomPlayer.swift:35) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
setupRateObserver (DirectionalRemotes/Custom Player/CustomPlayer.swift:59) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
Reference code
DirectionalRemotes/Custom Player/CustomPlayer.swift:27 — representative boundary
class CustomPlayer {
// ...
private var playerState: CustomPlayerState = .stopped // Default to stopped state
// ...
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Represents or runs a user/system command | RemoteCommand |
The source’s Command suffix makes this role explicit. |
| View lifecycle, callbacks, and feature coordination | CustomPlayerViewController, GuideViewController, MenuViewController, RemoteEventsViewController |
The source’s Controller suffix makes this role explicit. |
| Receives callback-driven events | AppDelegate |
The source’s Delegate suffix makes this role explicit. |
| Owns media or timeline playback | CustomPlayer, RemoteEventsPlayer |
The source’s Player suffix makes this role explicit. |
| User-interface presentation and input forwarding | CustomPlayerFeedbackView, CustomPlayerView, RemoteEventsView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | DirectionalRemotes/Custom Player/CustomPlayerViewController.swift:10 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Protocol-oriented abstraction | DirectionalRemotes/Custom Player/CustomPlayerViewController.swift:189 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Delegate or data-source callbacks | DirectionalRemotes/AppDelegate.swift:13 |
Callback protocols invert event delivery back into the sample’s owner. |
Naming conventions
- Types: Command: RemoteCommand; Controller: CustomPlayerViewController, GuideViewController, MenuViewController, RemoteEventsViewController, SystemPlayerViewController; Delegate: AppDelegate; Player: CustomPlayer, RemoteEventsPlayer; View: CustomPlayerFeedbackView, CustomPlayerView, RemoteEventsView.
- Protocols:
GuideReporting,CustomPlayerReporting,RemoteEventsPlayerReporting. - Methods:
application,applicationDidEnterBackground,applicationWillEnterForeground,loadView,viewDidLoad,setupGuideButtonObserver,guideButtonPressed,setupAppLifecycleEventsHandlers. - Files:
DirectionalRemotes/AppDelegate.swift,DirectionalRemotes/Custom Player/CustomPlayerViewController.swift,DirectionalRemotes/Remote Events/RemoteEventsViewController.swift,DirectionalRemotes/System Player/SystemPlayerViewController.swift,DirectionalRemotes/Guide/GuideViewController.swift,DirectionalRemotes/Custom Player/CustomPlayer.swift.
Architecture takeaways
AppDelegateis the main source-visible entry or composition anchor for this sample.- Framework work reaches UIKit, MediaPlayer, AVKit, AVFoundation through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- Local protocol relationships provide an explicit substitution boundary.
Source map
| Source file | Relevant symbols |
|---|---|
DirectionalRemotes/AppDelegate.swift |
Cited implementation, NotificationCenter, UIKit, AVFoundation, AppDelegate |
DirectionalRemotes/Guide/GuideViewController.swift |
GuideReporting, GuideScrollDirection, GuideViewController |
DirectionalRemotes/Custom Player/CustomPlayer.swift |
Cited implementation, DispatchQueue.main.async, MediaPlayer, CustomPlayerReporting, CustomPlayer |
DirectionalRemotes/Custom Player/CustomPlayerViewController.swift |
CustomPlayerViewController, Cited implementation, TVUIKit |
DirectionalRemotes/Custom Player/CustomPlayerUtilities.swift |
Foundation, TrickPlayMode, CustomPlayerFeedbackType, CustomPlayerState |
DirectionalRemotes/Custom Player/CustomPlayerView.swift |
AVKit, CustomPlayerView |
DirectionalRemotes/Remote Events/RemoteEventsViewController.swift |
RemoteEventsViewController |
DirectionalRemotes/System Player/SystemPlayerViewController.swift |
SystemPlayerViewController |
DirectionalRemotes/Remote Events/RemoteEventsPlayer.swift |
RemoteEventsPlayerReporting, RemoteEventsPlayer |
DirectionalRemotes/Custom Player/CustomPlayerFeedbackView.swift |
CustomPlayerFeedbackView |
DirectionalRemotes/MenuViewController.swift |
MenuViewController |
DirectionalRemotes/Remote Events/RemoteEventsView.swift |
RemoteEventsView |
DirectionalRemotes/Shared/RemoteCommand.swift |
RemoteCommand |
DirectionalRemotes/Guide/GuideChannelCell.swift |
GuideChannelCell |
DirectionalRemotes/Guide/GuideProgramCell.swift |
GuideProgramCell |
DirectionalRemotes/Remote Events/RemoteEventsCell.swift |
RemoteEventsCell |