Deep Link Routing
Relevant source files
The following files were used as context for generating this wiki page:
Deep Link Routing in the Social-Connect project provides a mechanism for the application to respond to external URLs and navigate the user to specific content or trigger actions within the app. The system captures incoming URLs through the application delegate and delegates the parsing and execution logic to a specialized handler.
The routing system supports various host-based actions such as viewing profiles, messaging, viewing posts, and following users. By integrating with the UserService and APIClient, the routing logic can perform authenticated network requests triggered directly by a deep link.
Sources: DeepLinkHandler.swift:1-18, AppDelegate.swift:13-16
Architecture Overview
The deep link architecture follows a centralized delegation pattern. The AppDelegate serves as the entry point for the operating system to pass URLs to the application. These URLs are then forwarded to the DeepLinkHandler, which parses the URL components to determine the intended destination or action.
Core Components
| Component | Responsibility |
|---|---|
AppDelegate | Intercepts the open url event from iOS and forwards it to the handler. |
DeepLinkHandler | Parses URL components (host and query items) and routes to specific private handlers. |
UserService | Provides business logic for actions like following/unfollowing users. |
APIClient | Manages authenticated HTTP requests to the backend API. |
KeychainManager | Retrieves authentication tokens required for API-linked deep link actions. |
Sources: AppDelegate.swift:13-16, DeepLinkHandler.swift:5-15, UserService.swift:6-10, APIClient.swift:15-18
Routing Flow Diagram
The following diagram illustrates the flow from an external URL trigger to the execution of a specific app action:
Navigation and Action Logic
The DeepLinkHandler uses the host property of the URL to determine the routing path. Parameters are extracted from the URL query items, typically identifying specific resources like a userId.
Supported Routes
- Profile: Extracts
userIdfrom query items and invokesnavigateToProfile(userId:). - Follow: Extracts
userIdand callsUserService.shared.followUser(userId:). - Message/Post: Placeholders for messaging and post-viewing implementations.
Sources: DeepLinkHandler.swift:27-55
Authenticated Actions
When a deep link triggers an action (like "follow"), the system ensures the request is authenticated. The APIClient automatically embeds a Bearer token retrieved from the KeychainManager into the request headers.
Implementation Details
URL Structure Parsing
The handler utilizes URLComponents to safely parse incoming strings. It requires a valid host to proceed; otherwise, the routing fails immediately.
func handleDeepLink(url: URL) -> Bool {
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true),
let host = components.host else {
return false
}
// ... switch host logic
}
Sources: DeepLinkHandler.swift:7-11
Notification System
Actions performed via deep links that modify user state (e.g., following a user) trigger system-wide notifications via NotificationCenter. This allows the UI to update reactively regardless of where the action originated.
Sources: UserService.swift:15-17
Summary
Deep Link Routing in Social-Connect is a structured system that bridges external URLs with internal application logic. By delegating from AppDelegate to a dedicated DeepLinkHandler, the app maintains a clean separation of concerns, enabling robust navigation and authenticated actions triggered by external sources.