Receiving links
Hand URLs to Lander, listen to Lander.deepLinks, understand cold start, warm start and deferred delivery, and route in SwiftUI or UIKit.
Receiving links has two halves. In: wherever iOS gives your app a URL or a Universal Link, pass it to Lander.handle(url:) or Lander.handle(userActivity:). Out: every link reaches you as a LanderLink on one stream, Lander.deepLinks, and you send it to your navigation.
The LanderLink
| Field | Type | Meaning |
|---|---|---|
route | String | Where to navigate: the link's path when resolved, otherwise the raw URL's path and query. |
url | URL | The URL that opened the app, exactly as iOS delivered it. For deferred links, the short link. |
isResolved | Bool | Whether Lander recognized the link (linkId != nil). |
linkId | String? | Lander link ID (a UUID). Pass it to trackEvent to attribute conversions. |
shortURL | URL? | Canonical short link, for example https://acme.golander.link/p-123. |
path | String? | The in app route set on the link, for example /product/123. |
params | [String: LanderParamValue] | Link params with the opened URL's query parameters merged over them. |
campaign, channel | String? | Attribution labels set on the link. |
isDeferred | Bool | True when the link was recovered after an install or handed off after sign in. |
confidence | LanderConfidence | .deterministic, .probabilistic or .unattributed. |
method | String? | How the link was tied to the open: universal_link, landing_page, authenticated_handoff or probabilistic_match. |
LanderLink is a Sendable, Hashable struct. Full details are in the API reference.
Hand links to Lander
Every handle method returns true when Lander took the link, and is marked @discardableResult, so you can ignore the result. Lander takes every web URL and custom scheme URL (unknown ones are still delivered, unresolved), only browsing web user activities, and never file URLs.
WindowGroup {
ContentView()
.onOpenURL { Lander.handle(url: $0) }
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { Lander.handle(userActivity: $0) }
}SwiftUI calls both on cold start and warm start. Nothing else to add.
Other SDKs' URLs
Lander takes every URL you give it. If another SDK handles URLs too (a sign in or payment redirect), give the URL to that SDK first and only pass it to Lander when the other one returns false. Anything you do pass to Lander also reaches deepLinks, so ignore routes you do not handle.
Listen to deepLinks
for await link in Lander.deepLinks {
router.open(link)
}Lander.deepLinks is an AsyncStream<LanderLink>. Each access returns a new stream; iterate it in one task. In SwiftUI, a .task on your root view is the natural place, because SwiftUI cancels it when the view goes away. Complete examples for SwiftUI and UIKit are below.
Prefer closures? Lander.onDeepLink calls your handler on the main actor for each link and returns a LanderSubscription:
let subscription = Lander.onDeepLink { link in
router.open(link)
}
// Later, if you ever need to stop:
subscription.cancel()The subscription lasts until you call cancel(). Releasing the token does not end it, so for an app wide handler you can ignore the return value.
Cold start, warm start and deferred
A link can reach your app in three situations. All three arrive on the same stream.
| Situation | What happened | Where iOS delivers it | Typical method |
|---|---|---|---|
| Cold start | The app was not running. The tap launched it. | SwiftUI: .onContinueUserActivity / .onOpenURL. UIKit: scene(_:willConnectTo:options:), or the app delegate. | universal_link |
| Warm start | The app was running or in the background. | SwiftUI: the same modifiers. UIKit: scene(_:continue:), scene(_:openURLContexts:) or the app delegate. | universal_link |
| Deferred | The app was not installed. The person installed it and opened it for the first time. | No URL at all: Lander returns the link in its answer to the first launch report (POST /v1/sdk/init). | probabilistic_match |
Cold start and deferred links are both "the link that launched the app", so they are delivered once, either on the stream or through initialLink(). Warm start links always go to the stream.
A native app cannot ask iOS for "the launch URL" the way a plugin can, so the SDK decides: the first link you hand to Lander while the app launches is the launch link. The launch ends about 1 second after the app first becomes active (or 5 seconds after initialize if it never does, for example a background launch). Links handled after that are warm start links.
If the app was opened by a link on its very first launch, that link wins and no deferred link is delivered on top of it.
The Continue in app page sits in between: after installing, the person taps "open it" on the page, so the link arrives as an ordinary cold start open, but with method: landing_page and isDeferred: true when the app was installed after the click.
Confidence levels
Every link carries a confidence, so you can decide how much to trust it:
LanderConfidence | When | What to do with it |
|---|---|---|
.deterministic | A tap on a Universal Link, the Continue in app page or an authenticated handoff. Lander knows. | Treat it as if the user tapped it in your app. |
.probabilistic | Opt in probabilistic matching guessed the link from coarse signals. Usually right, sometimes wrong. | Show the screen, but never sign someone in, apply a credit or reveal anything private because of it. |
.unattributed | Lander could not tie a link to this open. Unresolved links always have this. | Route on the raw URL if you want; there is no Lander data. |
More on how each one is decided in Attribution and Deferred links.
Buffered, exactly once delivery
You never have to race the SDK at startup:
- Buffered. Links that arrive while no stream is listening are kept and replayed, in order, to the next stream. This covers cold starts and links that arrive before your navigation is ready. You can even listen (and call
handle) beforeinitialize. - The launch link is delivered once. It goes to the stream unless
initialLink()claims it first. Whichever gets it first wins, so navigation never happens twice. - In arrival order. Links are resolved one after another, so they come out in the order they were tapped.
- Duplicates are dropped. The same URL handed over twice within two seconds counts as one open (for example from both
launchOptionsandapplication(_:open:options:)). - Opens are reported for you. Lander records the open when the SDK resolves the link. You do not need to track opens yourself.
When several streams (or onDeepLink handlers) are listening, each gets every live link. Buffered links go to the first one that starts listening, so keep a single listener at the root of your app. If it stops and a new one starts later, links that arrived in between are buffered and replayed.
initialLink: pick the first screen
Most apps only need the stream. Use initialLink() when you want to choose the first screen from the launch link, for example behind a splash screen:
struct RootView: View {
@State private var start: String?
var body: some View {
Group {
if let start { MainView(initialRoute: start) } else { SplashView() }
}
.task {
let link = await Lander.initialLink() // may wait for the network, see below
start = link?.route ?? "/"
}
}
}Once initialLink() has been called, the stream never delivers the launch link. If the stream already delivered it, initialLink() returns nil, and so does every call after the first.
initialLink() waits when it has to:
| Situation | Waits for |
|---|---|
| The app was opened by a link | The end of the launch, then the resolve request (POST /v1/sdk/resolve) |
| First launch, no link | The end of the launch and the launch report (POST /v1/sdk/init), because a deferred link may come back |
| Any later launch without a link | The end of the launch (about 1 second after the app becomes active), then returns nil |
Each request attempt has a 10 second timeout and failed requests are retried, so on a bad network this can take a while. Listening to deepLinks never blocks anything, which is why it is the recommended path.
Unresolved links
Not every URL is a Lander link, and the network is not always there. The SDK still delivers the link, with isResolved == false, confidence == .unattributed and only url set:
| Case | Why |
|---|---|
Lander answers 404 link_not_found | The URL is not a link of this project and environment: a page on your own site that your app also claims, a nested path, a typo, or a live link opened by an app using a pk_test_ key. |
Lander answers 410 | The link is disabled (link_disabled) or past its expiry (link_expired). |
| The request failed | Offline, timeout or a server error after retries. |
| Custom scheme URL | acmeshop://product/123 is delivered as is, with no network call. |
route still works for unresolved links. It uses the URL's path and query; for custom scheme URLs the host (lowercased) counts as the first path segment:
url | route |
|---|---|
acmeshop://product/123 | /product/123 |
acmeshop://product/123?color=red | /product/123?color=red |
https://acme.golander.link/old-slug (unknown) | /old-slug |
So design your navigation to cope with routes it does not know (a not found screen, or going home).
One exception: a custom scheme URL that carries a short link in a lander_link query parameter (the Continue in app page builds these) is resolved like the short link itself. url stays the scheme URL, and if resolving fails the scheme URL's own path still routes.
Route in SwiftUI
A small router that turns routes into a NavigationStack path (iOS 16 and later; on iOS 15 drive a NavigationView from the same state):
import Lander
import SwiftUI
enum Screen: Hashable {
case product(id: String, link: LanderLink?)
case notFound(String)
}
@MainActor
final class Router: ObservableObject {
@Published var path: [Screen] = []
func open(_ link: LanderLink) {
let parts = (link.route.split(separator: "?").first ?? "").split(separator: "/").map(String.init)
switch parts {
case ["product", let id]:
// https://acme.golander.link/p-123 resolves to /product/123.
path = [.product(id: id, link: link)]
case []:
path = []
default:
// Unresolved links route on the raw URL, which may match nothing.
path = [.notFound(link.route)]
}
}
}@main
struct AcmeShopApp: App {
@StateObject private var router = Router()
init() {
try? Lander.initialize(apiKey: "pk_live_...")
}
var body: some Scene {
WindowGroup {
NavigationStack(path: $router.path) {
HomeView()
.navigationDestination(for: Screen.self) { screen in
switch screen {
case .product(let id, let link): ProductView(id: id, link: link)
case .notFound(let route): NotFoundView(route: route)
}
}
}
.onOpenURL { Lander.handle(url: $0) }
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { Lander.handle(userActivity: $0) }
.task {
// Lander buffers links (including the one that launched the app) until
// this starts listening.
for await link in Lander.deepLinks { router.open(link) }
}
}
}
}A few choices to make:
- Replace or push. Setting
path = [...]replaces the stack, so back goes home. Appending pushes the screen on top of wherever the user is. Replacing is the safer default for links. - Pass the link along. The screen can then read
link.params,link.campaignorlink.linkId(to attribute a purchase withtrackEvent).
Links that need sign in
If a link points at a screen that needs an account, hold on to it and open it after sign in:
var pending: LanderLink?
func open(_ link: LanderLink) {
guard auth.isSignedIn else {
pending = link // open it once the user has signed in
showLogin()
return
}
route(link)
}
// After a successful sign in:
func didSignIn() {
if let link = pending { route(link) }
pending = nil
}Here auth stands for your own auth state. Signing in is also the moment to call Lander.claimHandoff(userId:) if you use handoffs.
Route in UIKit
With UIKit, subscribe once with onDeepLink, for example in the scene delegate after the window exists, and push a view controller for each route:
import Lander
import UIKit
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
private let navigation = UINavigationController(rootViewController: HomeViewController())
func scene(
_ scene: UIScene, willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let windowScene = scene as? UIWindowScene else { return }
let window = UIWindow(windowScene: windowScene)
window.rootViewController = navigation
window.makeKeyAndVisible()
self.window = window
Lander.onDeepLink { [weak self] link in self?.open(link) }
Lander.handle(connectionOptions: connectionOptions)
}
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
Lander.handle(userActivity: userActivity)
}
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
for context in URLContexts { Lander.handle(url: context.url) }
}
private func open(_ link: LanderLink) {
let parts = (link.route.split(separator: "?").first ?? "").split(separator: "/").map(String.init)
switch parts {
case ["product", let id]:
navigation.popToRootViewController(animated: false)
navigation.pushViewController(ProductViewController(id: id, link: link), animated: true)
default:
navigation.popToRootViewController(animated: true)
}
}
}Read the link's data
Params set on the link in Lander, plus any query parameters on the opened URL, are in link.params. Query parameters win when a key is in both, and arrive as strings. Each value is a LanderParamValue (.string, .int, .double or .bool) with typed accessors:
let productId = link.params["productId"]?.stringValue
let discount = link.params["discount"]?.intValue // "15" or 15 both give 15
let isGift = link.params["gift"]?.boolValue ?? false
if link.campaign == "summer_2026" {
// Show the campaign banner.
}For unresolved links params is empty. Read the raw URL instead:
let items = URLComponents(url: link.url, resolvingAgainstBaseURL: false)?.queryItems ?? []