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

Handling Communication Notifications and Focus Status Updates

At a glance

Item Summary
Purpose Create a richer calling and messaging experience in your app by implementing communication notifications and Focus status updates.
App architecture A Swift sample with the source-visible chain CommunicationNotificationsAppContentViewNotificationServiceUserNotifications APIs.
Main patterns Delegate or data-source callbacks, Service object, Repository
Project style 10 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── CommunicationNotifications/
│   ├── CommunicationNotificationsApp.swift
│   ├── AppDelegate.swift
│   └── ContentView.swift
├── NotificationService/
│   └── NotificationService.swift
├── Shared/
│   ├── AvatarRepository.swift
│   ├── CommunicationInformation.swift
│   ├── PersonInformation.swift
│   ├── CommunicationInteractor.swift
│   └── CommunicationMapper.swift
├── IntentHandler/
│   └── IntentHandler.swift
└── CommunicationNotifications.xcodeproj/
    ├── .xcodesamplecode.plist
    └── project.pbxproj

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 7 project/configuration file(s) and 22 source declaration(s).

Overall architecture

Reference code

CommunicationNotifications/CommunicationNotificationsApp.swift:10 — architecture anchor

@main
struct CommunicationNotificationsApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

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 User Notifications.

Ownership and state

Ownership evidence

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

class NotificationService: UNNotificationServiceExtension {
    // ...
    var contentHandler: ((UNNotificationContent) -> Void)?
    // ...
}
Owner Object or state Relationship Mutation authority
NotificationService Callback (contentHandler) stores a callback App/module collaborators
NotificationService UNMutableNotificationContent (bestAttemptContent) stores or receives App/module collaborators
NotificationService Logger (logger) creates and retains Owning lexical scope
AvatarRepository AvatarRepository (shared) creates and retains Initialized by the owner; the binding is immutable

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

CommunicationNotifications/CommunicationNotificationsApp.swift:11 — representative type boundary

struct CommunicationNotificationsApp: App {
    // ...
}
Type Responsibility Depends on or conforms to
CommunicationNotificationsApp Application entry and top-level composition App
AppDelegate Receives callback-driven events NSObject, UIApplicationDelegate
NotificationService Framework-facing operations UNNotificationServiceExtension
ContentView User-interface presentation and input forwarding View
AvatarRepository Data access boundary Concrete collaborators/imported frameworks
IntentHandler Handles callbacks or feature events INExtension
Icon Defines a closed set of feature states or choices Concrete collaborators/imported frameworks
AvatarRepositoryError Represents feature failure conditions Error
CommunicationType Defines a closed set of feature states or choices Concrete collaborators/imported frameworks
PeopleInvolved Defines a closed set of feature states or choices Concrete collaborators/imported frameworks

No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.

Access control

Symbol Access Verified effect Likely rationale
row (CommunicationNotifications/ContentView.swift:83) 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.
suggest (CommunicationNotifications/ContentView.swift:275) 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.
cacheSuggestedImage (CommunicationNotifications/ContentView.swift:288) 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.
exampleImageData (CommunicationNotifications/ContentView.swift:297) 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

CommunicationNotifications/ContentView.swift:83 — representative boundary

    private func row(icon: Icon, title: String) -> some View {
        // ...
    }

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 CommunicationNotificationsApp The source’s App suffix makes this role explicit.
Receives callback-driven events AppDelegate The source’s Delegate suffix makes this role explicit.
Handles callbacks or feature events IntentHandler The source’s Handler suffix makes this role explicit.
Data access boundary AvatarRepository The source’s Repository suffix makes this role explicit.
Framework-facing operations NotificationService The source’s Service suffix makes this role explicit.
User-interface presentation and input forwarding ContentView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Delegate or data-source callbacks CommunicationNotifications/AppDelegate.swift:11 Callback protocols invert event delivery back into the sample’s owner.
Service object NotificationService/NotificationService.swift:11 A role-named service contains framework-facing operations.
Repository Shared/AvatarRepository.swift:14 A repository-named type creates a data-access boundary.

Naming conventions

  • Types: App: CommunicationNotificationsApp; Delegate: AppDelegate; Handler: IntentHandler; Repository: AvatarRepository; Service: NotificationService; View: ContentView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: application, didReceive, serviceExtensionTimeWillExpire, communicationInformation, oneOnOneMessageExample, groupMessageExample, voicemailExample, oneOnOneMissedCallExample.
  • Files: CommunicationNotifications/CommunicationNotificationsApp.swift, CommunicationNotifications/AppDelegate.swift, NotificationService/NotificationService.swift, CommunicationNotifications/ContentView.swift, Shared/AvatarRepository.swift, Shared/CommunicationInformation.swift.

Architecture takeaways

  • CommunicationNotificationsApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches Intents, SwiftUI, UserNotifications, 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.
  • The source does not justify labeling the design protocol-oriented.

Source map

Source file Relevant symbols
CommunicationNotifications/CommunicationNotificationsApp.swift CommunicationNotificationsApp
CommunicationNotifications/AppDelegate.swift AppDelegate
NotificationService/NotificationService.swift NotificationService
CommunicationNotifications/ContentView.swift ContentView, Icon, ContentView_Previews
Shared/AvatarRepository.swift AvatarRepositoryError, AvatarRepository
Shared/CommunicationInformation.swift CommunicationType, PeopleInvolved, GroupInformation, OneOnOneInformation, CommunicationInformation
IntentHandler/IntentHandler.swift IntentHandler
Shared/PersonInformation.swift AvatarImage, PersonName, UniqueUserIdentifier, PersonInformation
Shared/CommunicationInteractor.swift CommunicationInteractorError, AuthorizationStatus, CommunicationInteractor
Shared/CommunicationMapper.swift CommunicationMapperError, CommunicationMapper