Creating New Deep Link Routes
Relevant source files
The following files were used as context for generating this wiki page:
The deep linking system in Social-Connect provides a centralized mechanism for handling external URLs and directing users to specific features or content within the application. By leveraging the DeepLinkHandler, the application can parse URL components and execute corresponding logic, such as navigating to user profiles or performing social actions like following a user.
This system integrates tightly with the application's lifecycle via the AppDelegate and utilizes the UserService for actions that require network interaction. New routes are defined by extending the parsing logic to recognize specific URL hosts and parameters.
Architecture Overview
The deep link architecture follows a delegation pattern where the AppDelegate intercepts incoming URLs and hands them off to a specialized handler class.
Entry Point
The application receives deep links through the standard UIKit application delegate method. The AppDelegate holds a reference to the DeepLinkHandler and invokes its processing method whenever a URL is opened.
Sources: AppDelegate.swift:7-19
Handling Logic
The DeepLinkHandler class is responsible for the decomposition of the URL. It uses URLComponents to extract the host (which serves as the route identifier) and query items (which serve as parameters).
Sources: DeepLinkHandler.swift:6-25
Defining New Routes
To create a new deep link route, developers must modify the DeepLinkHandler.swift file. The process involves defining a new host string and implementing a corresponding handler method.
Route Components
Deep links are structured using a scheme (e.g., socialconnect://), a host (the route), and optional query parameters.
| Component | Description | Example |
|---|---|---|
| Host | Acts as the primary route selector in the switch statement. | profile, follow, message |
| Query Item | Key-value pairs providing data to the route. | userId=123 |
Sources: DeepLinkHandler.swift:16-24, DeepLinkHandler.swift:31-33
Implementation Steps
- Update the Host Switch: Add a new case to the
switch hostblock within thehandleDeepLink(url:)function. - Extract Parameters: Create a private helper method that uses
components.queryItemsto retrieve necessary data. - Execute Action: Call the relevant service (e.g.,
UserService) or navigation logic.
// Example of extracting a parameter
guard let userId = components.queryItems?.first(where: { $0.name == "userId" })?.value else {
return false
}
Sources: DeepLinkHandler.swift:31-35
Backend Integration and Services
Many deep link routes trigger network requests or require authentication. The system relies on several supporting classes to complete these actions.
User Service and API Client
When a deep link like follow is triggered, it interacts with the UserService. This service uses the APIClient to perform authenticated POST requests.
| Service | Responsibility | Relevant Method |
|---|---|---|
UserService | Business logic for user actions. | followUser(userId:completion:) |
APIClient | Networking and Header management. | post(endpoint:completion:) |
KeychainManager | Secure token retrieval for API calls. | getAuthToken() |
Sources: UserService.swift:7-15, APIClient.swift:16-24, KeychainManager.swift:9-25
Data Flow for Social Actions
The following diagram illustrates the flow from a follow deep link to a network request:
Summary
Creating new deep link routes in Social-Connect requires registering a host identifier in DeepLinkHandler, parsing query parameters via URLComponents, and linking the result to the application's service layer. The architecture ensures that deep links benefit from existing authentication and networking infrastructure provided by the APIClient and KeychainManager.