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.
Execution model Source-visible boundaries: DispatchQueue.global.async; none alone proves a background thread.
State/event model No structured observation or publisher-scheduling marker indexed.
Key frameworks/packages Foundation, Intents, SwiftUI, UserNotifications, os; these are source dependencies, not architecture labels.

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.

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.global.async The source addresses a global dispatch queue; no stable thread identity is implied. Shared/CommunicationInteractor.swift:30

@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

Shared/CommunicationInteractor.swift:30 — representative execution boundary

                DispatchQueue.global(qos: .userInitiated).async {
                    if let error = error {
                        completion(.failure(error))
                    } else {
                        completion(.success(interaction))
                    }
                }

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
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. CommunicationNotifications/AppDelegate.swift:8
Source import Intents The cited file imports this module; runtime use and architectural role are not inferred. IntentHandler/IntentHandler.swift:8
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. CommunicationNotifications/CommunicationNotificationsApp.swift:8
Source import UserNotifications The cited file imports this module; runtime use and architectural role are not inferred. NotificationService/NotificationService.swift:8
Source import os The cited file imports this module; runtime use and architectural role are not inferred. NotificationService/NotificationService.swift:9
Source import UIKit The cited file imports this module; runtime use and architectural role are not inferred. CommunicationNotifications/AppDelegate.swift:9

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

CommunicationNotifications/CommunicationNotificationsApp.swift:11 — representative type boundary

@main
struct CommunicationNotificationsApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    // ...
}
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 {
        // ...
            Image(systemName: icon.systemImageName)
        // ...
    }

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 Cited implementation, CommunicationNotificationsApp, SwiftUI
NotificationService/NotificationService.swift Cited implementation, NotificationService, UserNotifications, os
CommunicationNotifications/ContentView.swift Cited implementation, ContentView, Icon, ContentView_Previews
CommunicationNotifications/AppDelegate.swift Cited implementation, Foundation, UIKit, AppDelegate
Shared/AvatarRepository.swift AvatarRepository, AvatarRepositoryError
Shared/CommunicationInteractor.swift DispatchQueue.global.async, CommunicationInteractorError, AuthorizationStatus, CommunicationInteractor
IntentHandler/IntentHandler.swift Intents, IntentHandler
Shared/CommunicationInformation.swift CommunicationType, PeopleInvolved, GroupInformation, OneOnOneInformation, CommunicationInformation
Shared/PersonInformation.swift AvatarImage, PersonName, UniqueUserIdentifier, PersonInformation
Shared/CommunicationMapper.swift CommunicationMapperError, CommunicationMapper