Testing
Test keys, SDK logs, simctl commands that open links, testing a first launch, the dashboard Debugger and unit tests for your routing.
Use the test environment
Build development versions of your app with a pk_test_ key and create test links for them. Test links, test installs and test events stay out of your live analytics. Switch the dashboard to the test environment to create and inspect them. See Environments.
Remember that resolving follows the key: a live link opened by an app using a pk_test_ key comes back unresolved, and the other way round.
Turn on logging
#if DEBUG
try? Lander.initialize(apiKey: "pk_test_...", enableLogging: true)
#else
try? Lander.initialize(apiKey: "pk_live_...")
#endifThe SDK then writes what it does to the unified log, prefixed with [Lander], under the subsystem link.golander.lander. The lines show up in Xcode's console while you debug. In the Console app, filter on that subsystem and turn on Action > Include Debug Messages. It never logs your API key. Lines you will see:
| Log line | Meaning |
|---|---|
Created install ID ... | First launch (or a reset install). A new random ID was stored. |
Init ok | The launch report reached Lander. Events can be sent from now on. |
Init failed: LanderError(invalid_api_key, 401): ... | The key is wrong or revoked. |
Deferred link: LanderLink(...) | The first launch report returned a deferred link. |
Resolved LanderLink(...) | A link was resolved. The line shows its ID, path, params, URL, confidence and method. |
Not a Lander link: https://... | Lander answered 404 for this URL. It is still delivered, unresolved. |
Resolve failed for https://...: LanderError(...) | Network error, timeout, or the link is disabled or expired (410). Delivered unresolved. |
Ignoring duplicate link ... | The same URL arrived twice within 2 seconds. |
Sent 3 events | A batch of events was accepted. |
Event batch failed (network_error), retrying in 2s | The queue will try again with backoff. |
Event batch rejected (...): check the API key. Pausing until next launch. | A 401 or 403 on events. Events are kept for the next launch. |
Install ID belongs to another project, creating a new one | You switched keys between test and live (or projects). Harmless. |
Integration mistakes are logged as errors even with logging off: an event dropped because it is invalid (Dropped event ...) and initialLink() called before initialize.
Open links from the terminal
You do not need to tap links in Notes or Messages to test. These commands deliver a URL to your app on the iOS Simulator exactly as a tap would:
# Universal Link (needs the apple-app-site-association file to be fetched)
xcrun simctl openurl booted "https://acme.golander.link/p-123"
# Custom scheme (always opens the app; good for testing routing)
xcrun simctl openurl booted "acmeshop://product/123"
# Cold start: stop the app first, then open the link
xcrun simctl terminate booted com.acme.shop
xcrun simctl openurl booted "https://acme.golander.link/p-123"Run each link twice: once with the app in the background (warm start) and once after stopping it (cold start). Both should land on the same screen, once.
On a real iPhone, paste the link into Notes or Messages and tap it. Typing a Universal Link into Safari's address bar does not open the app; that is iOS behavior, not a setup problem.
Debugging a cold start
When you launch the app from Xcode and then open a link, that is a warm start. To debug a cold start, edit the scheme's Run > Info and choose Wait for the executable to be launched, run, then open the link: Xcode attaches when the link launches the app.
Test a first launch
A first launch is what produces a deferred link and an install. Uninstalling removes the install ID, so a reinstall is a fresh first launch:
xcrun simctl uninstall booted com.acme.shopWays to see a deferred link while developing:
- Authenticated handoff (simulator or device): create a handoff with your
sk_test_key for a test user, sign in as that user in the app and callLander.claimHandoff(userId:). See Authenticated handoff. - Continue in app page (real device, with
iosLandingPageon): delete the app, tap a test link in Safari, install your build from Xcode instead of the App Store, go back to Safari and tap I already have the app, open it. - Probabilistic matching (with
probabilisticMatchingon): delete the app, tap a test link in Safari on the same device, then install and run your build within the matching window.
Check everything with the Debugger
Open Build > Debugger in the dashboard and paste a link. It checks everything between a tap and your app's screen: the link itself, your app configuration (Team ID and bundle ID), the apple-app-site-association file on the edge, and whether an app with the SDK has reported in the last 24 hours. Failed checks link to the fix.
Build > SDK shows the SDK versions that apps report in the current environment, so you can confirm a new build is talking to Lander. The iOS SDK reports itself as ios/0.1.0 in the X-Lander-Sdk header.
Unit test your routing
LanderLink has a public memberwise initializer and LanderLink.unresolved(_:), so you can test how your app routes links without a device or the network:
import Lander
import Testing
@testable import AcmeShop
@Test func resolvedLinkRoutesToItsPath() {
let link = LanderLink(
url: URL(string: "https://acme.golander.link/p-123")!,
linkId: "0b8f9a52-6f1c-4d3e-9a43-3f0d2b7c1e55",
shortURL: URL(string: "https://acme.golander.link/p-123"),
path: "/product/123",
params: ["productId": "123"],
confidence: .deterministic,
method: "universal_link"
)
#expect(link.isResolved)
#expect(link.route == "/product/123")
}
@Test func customSchemeRoutesWithoutLander() {
let link = LanderLink.unresolved(URL(string: "acmeshop://product/123?color=red")!)
#expect(!link.isResolved)
#expect(link.route == "/product/123?color=red")
}
@MainActor
@Test func routerOpensTheProductScreen() {
let router = Router()
router.open(.unresolved(URL(string: "acmeshop://product/123")!))
#expect(router.path == [.product(id: "123", link: .unresolved(URL(string: "acmeshop://product/123")!))])
}To test the view that listens, let it take the link stream as a parameter, defaulting to Lander.deepLinks, and pass a stream you control in tests:
struct RootView: View {
var links: AsyncStream<LanderLink> = Lander.deepLinks
@StateObject private var router = Router()
var body: some View {
HomeView()
.environmentObject(router)
.task { for await link in links { router.open(link) } }
}
}let (links, continuation) = AsyncStream.makeStream(of: LanderLink.self)
let view = RootView(links: links)
continuation.yield(.unresolved(URL(string: "acmeshop://product/123")!))Against a local Lander API
This is for working on Lander's own monorepo. With it running (pnpm dev), the API listens on port 8787 and a seeded test key exists:
try? Lander.initialize(
apiKey: "pk_test_DemoPublishableKey000000000000",
baseURL: URL(string: "http://localhost:8787")!,
enableLogging: true
)The iOS Simulator shares your Mac's localhost; a real device needs your Mac's address on the local network instead. Plain HTTP needs NSAllowsLocalNetworking under NSAppTransportSecurity in Info.plist (see Universal Links setup). Locally, link URLs on localhost or 127.0.0.1 resolve as acme.golander.link, and the seeded link https://acme.golander.link/p-123 resolves to /product/123:
xcrun simctl openurl booted "acmeshop://product/123?lander_link=http%3A%2F%2Flocalhost%3A8788%2Fp-123"That custom scheme URL carries a short link in lander_link, so the SDK resolves it against your local API without any Universal Link setup.