Durable LinksiOS Setup
Handling Durable Links
Receive and process Durable Links in your iOS app.
When a user taps a Durable Link, your app needs to handle the incoming URL and navigate the user to the right screen.
Handle incoming links
Pass incoming Universal Links to the SDK so it can resolve the Durable Link:
import SwiftUI
import AppPanel
@main
struct YourApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
handleDurableLink(url)
}
}
}
}You need to handle two cases: when the app is cold-launched from a link, and when the app is already running.
import AppPanel
// App is not running - cold launch from a universal link
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let _ = (scene as? UIWindowScene) else { return }
guard let userActivity = connectionOptions.userActivities.first,
userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let incomingURL = userActivity.webpageURL else {
return
}
handleDurableLink(incomingURL)
}
// App is running or suspended in memory
func scene(
_ scene: UIScene,
continue userActivity: NSUserActivity
) {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let incomingURL = userActivity.webpageURL else {
return
}
handleDurableLink(incomingURL)
}import AppPanel
func application(
_ app: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
guard let url = userActivity.webpageURL else { return false }
handleDurableLink(url)
return true
}func handleDurableLink(_ url: URL) {
AppPanel.shared.durableLinks.handleUniversalLink(url) { durableLink, error in
guard let durableLink = durableLink else { return }
DispatchQueue.main.async {
let alert = UIAlertController(
title: "Durable Link",
message: durableLink.url?.absoluteString,
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: "OK", style: .default))
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let rootVC = windowScene.windows.first(where: { $0.isKeyWindow })?.rootViewController {
rootVC.present(alert, animated: true)
}
}
}
}Replace the alert with your own navigation logic once you've verified links are working.
The DurableLink object
When a link is resolved, you receive a DurableLink with:
| Property | Type | Description |
|---|---|---|
url | URL | The deep link destination URL |
utmParameters | [String: String] | Extracted UTM parameters (source, medium, campaign, etc.) |
minimumAppVersion | String? | Minimum app version required, if set |
Disable pasteboard access
Post-install attribution is not possible without pasteboard access.
On iOS 14+, the SDK accesses the pasteboard on first app open, which triggers a system notification. To disable this:
AppPanel.shared.durableLinks.pasteboardRetrievalEnabled = false