Set up your app
iOS (Swift)
Set up DL2App Universal Links and deferred deep linking in a Swift app: Associated Domains, configure, and handling incoming links.
1. Associated Domains
In Xcode, open your target, Signing & Capabilities, add Associated Domains, and add one line per host:
applinks:myapp.dl2.app
applinks:myapp-alt.dl2.app
applinks:go.myapp.comThe Team ID and bundle ID you entered under Apps in the dashboard must match this target exactly. While developing, append ?mode=developer to an entry and enable Associated Domains Development on the device, so iOS fetches the association file directly instead of through Apple’s cache. Remove it for release builds.
2. Configure and listen
import DL2
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
DL2.configure(key: "pk_live_xxx",
options: DL2Options(linkDomains: ["myapp.dl2.app", "myapp-alt.dl2.app", "go.myapp.com"]))
_ = DL2.onLink { link in
// link.path, link.data, link.source (.deferred after an install)
Router.shared.open(path: link.path, data: link.data)
}
return true
}3. Forward incoming links
// Universal Links
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
DL2.handle(userActivity: userActivity)
}
// Custom scheme, if you use one
func application(_ app: UIApplication, open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
DL2.handle(url: url)
}With a scene delegate, call the same two methods from scene(_:continue:) and scene(_:openURLContexts:), and pass the user activity from connectionOptions on a cold start.
Optional: exact matching with the clipboard
Set DL2DeferredOptions(useClipboard: true) and show a DL2PasteButton on your first screen when no link was delivered. It is the system paste control, so iOS reads the clipboard only when the user taps it. The SDK never reads the pasteboard by itself.
Testing tips
- Tap the link from Notes or Messages. A link typed or pasted into Safari’s address bar never opens an app.
- If the app opened once and the user tapped the “back to Safari” breadcrumb, iOS remembers that choice for the domain. Long-press the link and choose “Open in app” to reset it.
DL2.reset()clears the install ID and first-launch flag so you can test deferred links again.
What the SDK does for you
- Delivers one event for all three cases: a link that cold-starts the app, a link while it is running, and a deferred link on first launch.
- Queues links that arrive before your listener is registered, so a cold-start link is never lost.
- Falls back to the URL’s own path and query if our API cannot be reached within 3 seconds, so the app still navigates.
- Never throws into your app: errors go to an
onErrorcallback. - Reads no advertising identifier. See Privacy and App Store disclosure.