App Lifecycle Management
Relevant source files
The following files were used as context for generating this wiki page:
The App Lifecycle Management system in Social-Connect governs how the application initializes, handles external entry points, and manages state transitions. It serves as the backbone for coordinating user authentication, deep linking, and network services from the moment the application is launched by the operating system.
The lifecycle is primarily managed by the AppDelegate, which acts as the central hub for system-level events. This system ensures that when the app is opened—whether through a standard launch or a specific URL—relevant services like DeepLinkHandler and UserService are invoked to provide a seamless user experience.
Sources: AppDelegate.swift:4-7, DeepLinkHandler.swift:3-5
Application Entry Points
The application utilizes the standard iOS UIApplicationDelegate protocol to manage its lifecycle. The entry points are divided between initial launch sequences and handling external URL requests.
Initialization Sequence
Upon launch, the AppDelegate initializes the window and private utility classes. The application(_:didFinishLaunchingWithOptions:) method provides a hook for customization immediately after the process starts.
The diagram shows the sequence of initialization from launch to the application being ready for user interaction.
Sources: AppDelegate.swift:7-13
External URL Handling
The application responds to deep links through the application(_:open:options:) method. This method delegates the URL processing to the DeepLinkHandler, allowing the app to navigate to specific content or perform actions based on external triggers.
Sources: AppDelegate.swift:15-18
Deep Link Orchestration
The DeepLinkHandler is responsible for parsing incoming URLs and routing the application to the correct state or view. It interacts with the UserService to perform actions like following users directly from a link.
Routing Logic
The handler extracts the host from the URL to determine the intended destination. Supported routes include profiles, messages, posts, and follow actions.
| Host | Action | Dependency |
|---|---|---|
profile | Navigates to a specific user's profile | navigateToProfile(userId:) |
follow | Triggers a follow request for a user | UserService.followUser(userId:) |
message | Opens message handling implementation | Internal UI logic |
post | Opens post viewing implementation | Internal UI logic |
Sources: DeepLinkHandler.swift:14-30
Follow Action Flow
When a "follow" deep link is detected, the system extracts the userId from the query items and invokes the shared UserService.
This sequence illustrates the flow from a system-level URL event to a network request and local state notification.
Sources: DeepLinkHandler.swift:32-40, UserService.swift:8-15
Service Integration and Security
During the lifecycle of a network request—often triggered by lifecycle events like deep links—the application maintains security through the KeychainManager and APIClient.
Authentication State
The APIClient automatically retrieves the authentication token from the KeychainManager for every outgoing POST request. If a token exists, it is added to the Authorization header as a Bearer token.
Sources: APIClient.swift:18-21, KeychainManager.swift:10-25
Data Persistence and Notifications
The UserService manages the lifecycle of user-related data. When actions like followUser or unfollowUser succeed, the service broadcasts a userFollowStatusChanged notification to update the UI across the application.
Sources: UserService.swift:12-14, UserService.swift:21-23
Summary
App Lifecycle Management in Social-Connect provides a structured approach to application startup and external event handling. By decoupling URL routing into a specialized DeepLinkHandler and centralizing network security in the APIClient and KeychainManager, the architecture ensures that the application state remains consistent and secure from the moment of entry.