API reference
Every public type, method, property and field in the Lander iOS SDK 0.1.0.
Everything below comes from one module:
import Lander| Export | Kind |
|---|---|
Lander | Static entry point (an enum with no cases) |
LanderLink | A link delivered to the app |
LanderShortLink | A link created with createLink |
LanderParamValue | A link param value: string, number or boolean |
LanderConfidence | Enum: how sure Lander is |
LanderError | Error thrown by initialize, createLink and claimHandoff |
LanderSubscription | Token returned by onDeepLink |
Every public type is Sendable, and the SDK builds in Swift 6 language mode with strict concurrency checking. Every Lander member can be called from any thread or actor, except the @MainActor UIKit helpers noted below.
Lander
public enum LanderAll members are static. You never create an instance.
Lander.initialize
static func initialize(
apiKey: String,
baseURL: URL = Lander.defaultBaseURL,
enableLogging: Bool = false
) throwsStarts the SDK. Call it once, as early as possible: in your App's init() or in application(_:didFinishLaunchingWithOptions:). Returns at once; loading the install ID, taking links and reporting the launch with POST /v1/sdk/init happen in the background.
Prop
Type
- Throws
LanderErrorwith codeinvalid_argumentwhenapiKey, trimmed, is a secret key or not a publishable key (pk_test_orpk_live_followed by at least 24 letters or digits). The key is never included in the error. - Never throws for network errors.
- A second call is ignored.
Lander.handle(url:)
@discardableResult
static func handle(url: URL) -> BoolHands a URL that opened the app to Lander: a Universal Link or a custom scheme URL. Call it from .onOpenURL, application(_:open:options:) or scene(_:openURLContexts:). Returns true for every URL with a scheme other than file. Safe to call before initialize: the URL is kept until the SDK starts.
Lander.handle(userActivity:)
@discardableResult
static func handle(userActivity: NSUserActivity) -> BoolHands a Universal Link to Lander, from .onContinueUserActivity(NSUserActivityTypeBrowsingWeb), application(_:continue:restorationHandler:) or scene(_:continue:). Returns true when activityType is NSUserActivityTypeBrowsingWeb and webpageURL is set.
Lander.handle(connectionOptions:)
@MainActor @discardableResult
static func handle(connectionOptions: UIScene.ConnectionOptions) -> BoolHands the URLs and Universal Links in a scene's connection options to Lander. Call it from scene(_:willConnectTo:options:): on a cold start, UIKit delivers the launch link there and nowhere else. Returns true when Lander took at least one link.
Lander.handle(launchOptions:)
@MainActor @discardableResult
static func handle(launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> BoolHands the URL (.url) or Universal Link (.userActivityDictionary) an app delegate based app was launched with to Lander. Optional: UIKit also calls application(_:open:options:) or application(_:continue:restorationHandler:) after launch, and the same URL handed over twice within 2 seconds counts once.
Lander.deepLinks
static var deepLinks: AsyncStream<LanderLink> { get }Every link the app receives: Universal Links, custom scheme URLs and deferred links.
- Each access returns a new stream. Iterate it in one task; it ends when that task is cancelled or the stream is released.
- Safe to use at any time, even before
initialize. - Links that arrive while no stream is listening are buffered and replayed, in order, to the next one. When several streams listen, each gets every link.
- Includes the launch link unless
initialLink()claimed it first. - Unknown links and links that could not be resolved are delivered with
isResolved == falseand onlyurlset. - Does not include links returned by
claimHandoff.
Lander.onDeepLink
@discardableResult
static func onDeepLink(
_ handler: @escaping @MainActor @Sendable (LanderLink) -> Void
) -> LanderSubscriptionCalls handler on the main actor for every link, as deepLinks delivers them. The subscription lasts until you call cancel() on the returned LanderSubscription; releasing it does not end it.
Lander.initialLink
static func initialLink() async -> LanderLink?The link that launched the app, or nil. The launch link is the first link handed to handle while the app launches (until about 1 second after it first becomes active, or 5 seconds after initialize at most). On a first launch it may instead be a deferred link, so it waits for the launch report in that case. Delivered once: returns nil if deepLinks or an earlier call already delivered it, and after this call deepLinks will not deliver it.
Returns nil and logs a warning before initialize. Waiting is not cancellable: a cancelled task still gets its answer.
Lander.createLink
static func createLink(
path: String = "/",
params: [String: LanderParamValue] = [:],
title: String? = nil,
campaign: String? = nil,
channel: String? = nil,
tags: [String] = [],
iosFallbackURL: URL? = nil,
androidFallbackURL: URL? = nil,
webFallbackURL: URL? = nil,
ogTitle: String? = nil,
ogDescription: String? = nil,
ogImageURL: URL? = nil,
expiresAt: Date? = nil
) async throws -> LanderShortLinkCreates a short link with POST /v1/sdk/links. The slug is random and the domain is the project's default domain.
Prop
Type
- Throws
LanderError(invalid_argument) whenpathdoes not start with/. - Throws
LanderError(not_initialized) beforeinitialize. - Throws
LanderErrorwhen the request fails after retries, orinvalid_responsewhen the response is not a link.
See Creating links.
Lander.claimHandoff
static func claimHandoff(userId: String) async throws -> LanderLink?Claims the link your backend bound to this user with POST /v1/handoffs, after sign in. Returns the link (isDeferred true, confidence .deterministic, method authenticated_handoff) or nil when nothing is pending. The newest pending handoff wins and every pending one for the user is cleared.
- The link is only returned, never also delivered on
deepLinks. - Throws
LanderError(invalid_argument) whenuserId, trimmed, is empty or longer than 256 characters. - Throws
LanderErrorwhen the request fails after retries, with codeinstall_not_registeredwhen the install could not be registered yet (the SDK retries that first),invalid_responsefor a response it cannot use, ornot_initializedbeforeinitialize.
See Deferred links.
Lander.trackEvent
static func trackEvent(
_ name: String,
properties: [String: any Sendable] = [:],
linkId: String? = nil
)Records a custom event in the on device queue, which sends it in batches with retries. Fire and forget: returns at once, never throws. Events tracked before initialize are queued until it runs.
Prop
Type
An invalid event (bad name, a linkId that is not a UUID, properties that cannot be sent as JSON) is dropped with a warning in the log, written even when logging is off. See Events.
Lander.installID
static var installID: String? { get }The random UUID v4 of this install (lowercase), once the SDK has started; nil before. Stored outside backups and removed on uninstall.
Lander.sdkVersion and Lander.defaultBaseURL
static let sdkVersion: String // "0.1.0"
static let defaultBaseURL: URL // https://api.golander.linksdkVersion is reported to the API as sdkVersion and in the X-Lander-Sdk header (ios/0.1.0).
LanderLink
public struct LanderLink: Sendable, Hashable, CustomStringConvertibleA deep link delivered to the app. When Lander knows the link, the fields mirror the ResolvedLink returned by the API. When it does not (unknown link, custom scheme URL, network unavailable) only url is set and isResolved is false.
Initializers
public init(
url: URL,
linkId: String? = nil,
shortURL: URL? = nil,
path: String? = nil,
params: [String: LanderParamValue] = [:],
campaign: String? = nil,
channel: String? = nil,
isDeferred: Bool = false,
confidence: LanderConfidence = .unattributed,
method: String? = nil
)
/// A link Lander could not resolve. Only url is set.
public static func unresolved(_ url: URL) -> LanderLinkThe public initializers make it easy to build links in your own tests. See Testing.
Properties
Prop
Type
route examples:
url | path | route |
|---|---|---|
https://acme.golander.link/p-123 | /product/123 | /product/123 |
https://acme.golander.link/unknown | nil | /unknown |
acmeshop://product/123?color=red | nil | /product/123?color=red |
acmeshop:// | nil | / |
Equality and description
LanderLink is Hashable: two links are equal when every field is equal. description gives a readable summary, for example LanderLink(<id>, path: /product/123, params: [productId: 123], url: https://acme.golander.link/p-123, deterministic via universal_link) or LanderLink(unresolved, url: acmeshop://product/123).
LanderShortLink
public struct LanderShortLink: Sendable, Hashable, CustomStringConvertibleA short link created with Lander.createLink. It has a public memberwise initializer for tests.
Prop
Type
description returns url.absoluteString.
LanderParamValue
public enum LanderParamValue: Sendable, Hashable, CustomStringConvertible,
ExpressibleByStringLiteral, ExpressibleByIntegerLiteral,
ExpressibleByFloatLiteral, ExpressibleByBooleanLiteral
{
case string(String)
case int(Int)
case double(Double)
case bool(Bool)
}A link param value, as the API stores them. Literals convert on their own, so ["productId": "123", "qty": 2, "gift": true] is a [String: LanderParamValue].
| Accessor | Type | Returns |
|---|---|---|
stringValue | String | Strings as they are; numbers and booleans in their JSON form (2, 49.99, true). Also description. |
intValue | Int? | An integer, a whole double, or a string holding an integer. |
doubleValue | Double? | A number, or a string holding one. |
boolValue | Bool? | A boolean, or the string true or false. |
Query parameters on the opened URL always arrive as .string, so prefer the accessors over matching cases.
LanderConfidence
public enum LanderConfidence: String, Sendable, Hashable, Codable, CaseIterable {
case deterministic, probabilistic, unattributed
}| Value | Meaning |
|---|---|
.deterministic | Matched by an exact identifier: a Universal Link open, the Continue in app page or an authenticated handoff. |
.probabilistic | Matched by coarse signals (OS version, country, click time, optionally a network hash) within a short window. Only iOS deferred links of projects that opted in. |
.unattributed | No link could be tied to this open. Any value the SDK does not know maps to this. |
LanderError
public struct LanderError: Error, Sendable, Equatable, CustomStringConvertible, LocalizedError {
public init(code: String, message: String, statusCode: Int? = nil, retryAfter: TimeInterval? = nil)
}Thrown by initialize (for a bad key), createLink and claimHandoff. trackEvent and the launch report never throw on network or server errors.
Prop
Type
description returns LanderError(code, statusCode): message.
API error codes you may see from the SDK endpoints: validation_error, invalid_domain, destination_blocked (400), invalid_api_key (401), wrong_key_kind, project_suspended (403), install_not_found (404), rate_limited, link_quota_exceeded (429), internal_error (500).
LanderSubscription
public final class LanderSubscription: Sendable {
public func cancel()
}Returned by Lander.onDeepLink. cancel() stops calling the handler. Releasing the object does not cancel it.
Network behavior
The SDK only talks to Lander's public API, never to a database.
| Endpoint | Called by | Attempts |
|---|---|---|
POST /v1/sdk/init | initialize, every launch; again on returning to the foreground, claimHandoff and event sends while no report has succeeded | 3 on a first launch, 1 otherwise |
POST /v1/sdk/resolve | Every http or https link handed to handle, and short links carried in lander_link | 2 |
POST /v1/sdk/events | The event queue | 1 per flush; the queue retries with backoff |
POST /v1/sdk/links | createLink | 3 |
POST /v1/sdk/handoffs/claim | claimHandoff | 3 |
- Every request sends
Authorization: Bearer <publishable key>,Content-Type: application/jsonandX-Lander-Sdk: ios/0.1.0, through an ephemeralURLSession. - Every attempt has a 10 second timeout.
- Retries happen only for network errors, timeouts,
invalid_response, 408, 429 and 5xx, with exponential backoff from 500 ms up to 4 s (or longer ifRetry-Afterasks). One call waits at most 10 seconds in total between attempts; a longerRetry-Afterends the retries.link_quota_exceededis never retried. - A 2xx response must be a JSON object (a 204 may be empty), otherwise the call fails with
invalid_response. appVersionandosVersionare cut to 50 characters.- Every write carries an
Idempotency-Keythat stays the same across retries, so a retry never creates a second link or claim.POST /v1/sdk/initignores the key: the API keeps one record per install ID, so a repeated launch report never creates a second install.