Sample CodeiOS, iPadOS, Mac Catalyst, macOSReviewed 2026-07-21View on Apple Developer

Receiving Voice and Text Communications on a Local Network

At a glance

Item Summary
Purpose Provide voice and text communication on a local network isolated from Apple Push Notification service by adopting Local Push Connectivity.
App architecture A C/Objective-C header, Swift sample with the source-visible chain SimplePushAppDirectoryViewDirectoryViewModelSimplePushProviderNetwork APIs.
Main patterns Model-View-ViewModel, Protocol-oriented abstraction, Delegate or data-source callbacks, Coordinator, SwiftUI environment injection, Publisher-backed observable state
Project style 52 scanned source file(s) across C/Objective-C header, Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── SimplePush/
│   └── SimplePush/
│       ├── SimplePushApp.swift
│       ├── UI/
│       │   ├── DirectoryViewModel.swift
│       │   ├── SettingsViewModel.swift
│       │   ├── UserViewModel.swift
│       │   ├── MessagingViewModel.swift
│       │   └── AppManager.swift
│       ├── Managers/
│       │   └── CallManager.swift
│       └── AppDelegate.swift
├── SimplePushKit/
│   └── SimplePushKit/
│       └── Networking/
│           ├── RequestResponseSession.swift
│           └── ConnectionOptions.swift
└── SimplePushServer/
    └── SimplePushServer/
        ├── Client.swift
        └── main.swift

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: C/Objective-C header, Swift.
  • The verified tree contains 15 project/configuration file(s) and 83 source declaration(s).

Overall architecture

Reference code

SimplePush/SimplePush/SimplePushApp.swift:11 — architecture anchor

@main
struct SimplePushApp: App {
    // ...
}

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 Network Extension.

Ownership and state

Ownership evidence

SimplePush/SimplePush/SimplePushApp.swift:13 — stored dependency or nearest verified ownership anchor

@main
struct SimplePushApp: App {
    @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
    // ...
}
Owner Object or state Relationship Mutation authority
SimplePushApp AppDelegate (appDelegate) stores or receives Owning lexical scope
SimplePushApp RootViewCoordinator (rootViewCoordinator) owns wrapper-managed state Owning lexical scope
DirectoryViewModel State (state) stores or receives App/module collaborators
DirectoryViewModel User (connectedUser) stores or receives App/module collaborators

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.

Class and protocol design

SimplePushKit/SimplePushKit/Coding/KeyCodable.swift:21 — representative type boundary

protocol KeyCodable {
    associatedtype Key: Hashable
    var keymap: [Key: Codable.Type] { get }
}
Type Responsibility Depends on or conforms to
SimplePushApp Application entry and top-level composition App
DirectoryViewModel UI-facing state and feature coordination ObservableObject
CallManager Long-lived feature or framework coordination NSObject
SettingsViewModel UI-facing state and feature coordination ObservableObject
UserViewModel UI-facing state and feature coordination ObservableObject
PresentedView User-interface presentation and input forwarding Identifiable
RequestResponseSession Owns a session-scoped interaction NetworkSession
Command Represents or runs a user/system command String, Codable
MessagingViewModel UI-facing state and feature coordination ObservableObject
Client External-system or framework client Concrete collaborators/imported frameworks

The source explicitly defines local protocol relationships: InviteRoutable, KeyCoderKeyCodable, TextMessageRoutable, RootViewCoordinatorPresenter, UserViewModelPresenter.

Access control

Symbol Access Verified effect Likely rationale
messagePublisher (SimplePush/Common/Networking/BaseChannel.swift:23) private(set) Read access follows the declaration; writes remain in the private scope. Inference: allow observation while reserving invariant-changing writes for the owner.
statePublisher (SimplePush/Common/Networking/BaseChannel.swift:24) private(set) Read access follows the declaration; writes remain in the private scope. Inference: allow observation while reserving invariant-changing writes for the owner.
networkSession (SimplePush/Common/Networking/BaseChannel.swift:25) 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.
heartbeatMonitor (SimplePush/Common/Networking/BaseChannel.swift:26) 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.

Reference code

SimplePush/Common/Networking/BaseChannel.swift:23 — representative boundary

    private(set) lazy var messagePublisher: AnyPublisher<Codable, Never> = internalMessageSubject.dropNil()
    private(set) lazy var statePublisher: AnyPublisher<NetworkSession.State, Never> = stateSubject.eraseToAnyPublisher()
    private let networkSession = RequestResponseSession()
    private let heartbeatMonitor: HeartbeatMonitor
    private let shouldConnectToServerSubject = CurrentValueSubject<Bool, Never>(false)
    private let hostSubject = CurrentValueSubject<String, Never>("")

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
Application entry and top-level composition SimplePushApp The source’s App suffix makes this role explicit.
External-system or framework client Client The source’s Client suffix makes this role explicit.
Represents or runs a user/system command Command The source’s Command suffix makes this role explicit.
Cross-object flow or session coordination HeartbeatCoordinator, RootViewCoordinator The source’s Coordinator suffix makes this role explicit.
Receives callback-driven events AppDelegate The source’s Delegate suffix makes this role explicit.
Long-lived feature or framework coordination CallManager, MessagingManager, PushConfigurationManager, SettingsManager The source’s Manager suffix makes this role explicit.
Monitors framework or system state HeartbeatMonitor The source’s Monitor suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Model-View-ViewModel SimplePush/SimplePush/UI/DirectoryViewModel.swift:12 Role-named view models keep UI-facing state or coordination outside view declarations.
Protocol-oriented abstraction SimplePushKit/SimplePushKit/Models/Invite.swift:10 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks SimplePush/SimplePush/AppDelegate.swift:13 Callback protocols invert event delivery back into the sample’s owner.
Coordinator SimplePushKit/SimplePushKit/Networking/HeartbeatCoordinator.swift:11 A role-named coordinator centralizes cross-object flow.
SwiftUI environment injection SimplePush/SimplePush/UI/DirectoryView.swift:14 The environment supplies state or a capability without threading it through every initializer.
Publisher-backed observable state SimplePush/SimplePush/Managers/CallManager.swift:41 Published properties notify observers while mutation remains with the state object.

Naming conventions

  • Types: App: SimplePushApp; Client: Client; Command: Command; Coordinator: HeartbeatCoordinator, RootViewCoordinator; Delegate: AppDelegate; Manager: CallManager, MessagingManager, PushConfigurationManager, SettingsManager, UserManager; Monitor: HeartbeatMonitor; Provider: SimplePushProvider.
  • Protocols: KeyCodable, Routable, Presenter.
  • Methods: view, userView, sendCall, receiveCall, endCall, cleanUpActiveCall, requestCallKitTransaction, updateCallHandle.
  • Files: SimplePush/SimplePush/SimplePushApp.swift, SimplePush/SimplePush/UI/DirectoryViewModel.swift, SimplePush/SimplePush/Managers/CallManager.swift, SimplePush/SimplePush/UI/SettingsViewModel.swift, SimplePush/SimplePush/UI/UserViewModel.swift, SimplePushKit/SimplePushKit/Networking/RequestResponseSession.swift.

Architecture takeaways

  • SimplePushApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SimplePushKit, SwiftUI, Network, UIKit 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
SimplePush/SimplePush/SimplePushApp.swift SimplePushApp
SimplePush/SimplePush/UI/DirectoryViewModel.swift DirectoryViewModel, State, NetworkConfigurationMode
SimplePush/SimplePush/Managers/CallManager.swift CallManager, State, InternalCallAction, CallRole, TerminatedReason
SimplePush/SimplePush/UI/SettingsViewModel.swift SettingsViewModel, SettingsGroup
SimplePush/SimplePush/UI/UserViewModel.swift UserViewModel, PresentedView
SimplePushKit/SimplePushKit/Networking/RequestResponseSession.swift RequestResponseSession, Error, PendingRequest, Command, Wrapper
SimplePush/SimplePush/UI/MessagingViewModel.swift MessagingViewModel
SimplePushServer/SimplePushServer/Client.swift Client, State, Connection, Error
SimplePushServer/SimplePushServer/main.swift Feature implementation
SimplePush/SimplePush/AppDelegate.swift AppDelegate