How kavindudissanayake/liveactivitysample-swiftui works
Based on our analysis of the file tree and README, this project is an iOS application focused on implementing Apple Live Activities with a dedicated backend for push notifications. It is composed of several key components:
Main Components
• iOS Frontend: The Xcode project “LiveActivity-Sample” (and the “LiveActivity” folder) represents the iOS part. This includes:
• The primary application (LiveActivity_SampleApp.swift, AppDelegate.swift), UI views (in the Views folder such as MainView, PassengerView, RiderDetailsView, and RiderListView), view models (MVVM-style architecture as seen in the ViewModel folder for ride tracking and rider views), assets, and utility functions (ActivityManager and extensions).
• A separate module (the “LiveActivity” folder) which likely contains the widget or live activity-specific components (for example, PassengerLiveActivityView and ProgressBarView) that interface with the live activity service.
• Backend: The “live-activity-backend” directory is a Node.js/Firebase Functions based service. Its role is to manage push notifications and live activity updates by plugging into the Apple Push Notification (APN) infrastructure. It is configured using the “Auth.p8” key and associated parameters (teamID, keyID, bundleID). This backend communicates with Apple’s servers to send updates (start, update, end) as defined by the live activity lifecycle.
• Testing/Utility Module: The “TestingJsonCreate” package (Swift-based) provides tools to generate sample JSON payloads (start, update, and end) that can be tested against the Apple Push Notification Console. This tool assists in verifying the format and timing of payloads used in the live activity updates.
Relationships and Interactions
• The iOS app interacts with Apple’s Live Activities and APNs – it uses the tokens (start token, update token) generated and updated through communication with the backend service.
• The backend (Firebase functions) handles critical data for push notification requests. It takes configuration parameters like teamID, keyID, and p8FilePath to properly authenticate with APNs before sending notifications.
• The TestingJsonCreate module simulates backend JSON payloads which are sent to or received by the iOS app, ensuring end-to-end validation.
Architectural Patterns
• MVVM Pattern: Evident in the separation of Views, ViewModels, and Models within the iOS app. This separation helps maintain clear data flows and user interface interactions.
• Separation of Concerns: The project clearly isolates the iOS client (UI, view models, utilities, and live activity view) from the backend server (Firebase functions for push notifications), and further includes a specialized tool for testing JSON payloads.
• Integration with External Services: The backend’s communication with Apple’s APNs demonstrates the use of external service integration and secure communication using keys/configurations.