Here's a summary of what was going on and how I fixed the issue (Logs are clean now!).
The issue was not with the Universal Link configuration itself (the AASA file and Associated Domains were correct), but with a race condition in the SwiftUI app's lifecycle.
The Problem: A Timing Issue
When the Universal Link is tapped, iOS launches the app and immediately passes the URL via the .onContinueUserActivity modifier.
In my original code, this modifier was on the root view in Strike_ForceApp.swift. It would parse the link and post a Notification for the UI to handle.
However, at this early stage of the app launch, the destination view (FriendsAndChallengesView) that was supposed to be listening for this notification had not been initialized yet, especially if the user needed to go through a loading or login screen first.
As a result, the notification was being posted before any part of the UI was ready to listen for it. The link would open the app, but the "message" to navigate or show an alert was lost.
The Solution: Centralizing the Logic in a View Model
The fix was to refactor the deep link handling to be independent of the view lifecycle by centralizing the logic in a persistent view model.
Centralized State: I moved all the logic for parsing and processing the deep link into the MainTabViewModel. This view model is created once and stays in memory for the entire time the main tab view is on screen. It now has @Published properties to hold the state of any pending deep link (e.g., a profile ID to show or a friend request to accept).
Delayed Handling: The .onContinueUserActivity modifier was moved from the root App struct to the MainTabView. This ensures that Universal Links are only caught and processed when the main, authenticated part of the app is actually on screen and ready.
State-Driven UI: The MainTabView now observes the @Published properties in the MainTabViewModel. When the view model processes a deep link and updates its state, the MainTabView automatically reacts by presenting the correct UI—either a .sheet for a user profile or an .alert for a friend request.
This new architecture completely resolves the race condition. The logic is no longer dependent on a specific view being on screen at the exact moment the link is opened. Instead, the state is managed centrally, and the UI reacts whenever that state changes, which has made the Universal Link handling robust and reliable.
Topic:
Code Signing
SubTopic:
Entitlements
Tags: