iOS SDK
The iOS SDK is currently in beta. Its public API may change between 0.x releases, so pin an exact version in production (exact: "0.3.0" in Package.swift, or Exact Version in Xcode's package dialog) and review the changelog before upgrading. We commit to API stability at 1.0.
Overview
The LinkSense iOS SDK delivers four capabilities:
- Install-time attribution — match a user's post-install session to the link they tapped before downloading your app.
- Deferred deep linking — surface the original link URL via a callback after install.
- Universal Link forwarding — resolve Universal Link taps for your in-app routing, and report each app open to your LinkSense analytics.
- Link CRUD — create, read, update, and delete dynamic links directly from the device.
The SDK ships as a Swift Package with zero third-party dependencies. It does not collect IDFA and never reads the clipboard without explicit opt-in.
For attribution the SDK sends the device's IDFV (identifier for vendor) to LinkSense on install and on each app open. It is sent as-is — despite the device_id_hash field name, no client-side hashing happens. The bundled privacy manifest declares it as Device ID, linked to the user, not used for tracking, plus non-linked diagnostic data. Mirror that in your App Store privacy label.
Prerequisites
- iOS 16.0 or later deployment target
- Xcode 15 or later, Swift 5.9+
- An SDK key from your LinkSense project (open your project's SDK Keys tab)
- Universal Links configured for your project subdomain (see iOS Deep Linking)
Installation
Add the SDK via Swift Package Manager. In Xcode, choose File → Add Package Dependencies… and paste the repository URL:
https://github.com/LinkSense-net/linksense-ios-sdk.gitOr add the dependency directly in your Package.swift:
.package(url: "https://github.com/LinkSense-net/linksense-ios-sdk.git", exact: "0.3.0")The iOS SDK ships only via Swift Package Manager. There is no podspec. If your project still uses CocoaPods, add the package via Xcode's Add Package Dependencies dialog alongside your existing Podfile. Expo and React Native apps use the React Native SDK instead, which bundles this SDK.
Configuration
Call configure once at app launch, then start to begin install-time attribution. configure throws, so call it with try:
import LinkSense do { try LinkSense.shared.configure( LinkSenseConfiguration( sdkKey: "ls_sdk_<project>_<random>", enableClipboard: false, logLevel: .off ) ) LinkSense.shared.start()} catch { // LinkSenseError.invalidSdkKey: the key is malformed. assertionFailure("LinkSense: \(error)")}Configuration fields:
| Field | Type | Required | Description |
|---|---|---|---|
sdkKey | String | Required | Your project SDK key (format: ls_sdk_<project>_<random>). Generate one in your project's SDK Keys tab. |
enableClipboard | Bool | Optional | Read the pasteboard once on first launch for clipboard-based deferred attribution, only when it holds a web URL. iOS shows its paste prompt when this reads. Default false; see Paste-to-attribute for a prompt-free alternative. |
logLevel | LogLevel | Optional | Diagnostic logging level (.off, .error, .info, .debug). Default .off — recommended for production. |
Subsequent calls to configure after the first are no-ops by design. The SDK reuses the same install idempotency key across cold starts to prevent double-attribution.
A malformed key throws LinkSenseError.invalidSdkKey and leaves the SDK unconfigured, so start() does nothing and every CRUD call fails with .notConfigured. A valid key looks like ls_sdk_ + 8 lowercase hex characters + _ + 32 lowercase hex characters — copy it from the dashboard rather than retyping it.
Handling Deferred Deep Links
Register a handler to receive the original dynamic link URL once attribution resolves. The callback fires on the main queue. Only one handler is kept — registering again replaces it — and a result that resolved before you registered is delivered as soon as you do.
LinkSense.shared.onDeferredDeepLink { url in if let url = url { router.handle(url) }}On the first launch after install, the handler receives the matched link — or nil if no click matched. On every later launch start() skips the network and the handler fires with nil again. So treat nil as "nothing to route", not as "organic install": if you need a once-per-install branch, keep your own first-launch flag.
Forwarding Universal Links
When iOS opens your app via a Universal Link, forward the NSUserActivity to the SDK. Where you receive it depends on your app's lifecycle — pick the tab that matches yours:
WindowGroup { ContentView() .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in LinkSense.shared.continueUserActivity(activity) { url in if let url = url { router.handle(url) } } }}On the first launch after install, a Universal Link tap is also used for attribution and the handler receives the matched deep link. After that, the handler receives the tapped URL unchanged. The method returns false — without calling the handler — when the activity is not a web-browsing activity or the SDK is not configured.
Each forwarded link is also reported to LinkSense as an app open. iOS opens Universal Links on-device without contacting LinkSense, so this is how those opens reach your analytics. The report never delays your handler.
For AASA hosting and the Associated Domains entitlement, see iOS Deep Linking.
Paste-to-Attribute
On iOS 16+, reading the clipboard shows a system prompt. If your onboarding asks users to paste an invite link, hand the pasted text to the SDK: the user's own paste supplies consent, so there is no prompt, and the install is attributed to that link.
// SwiftUI: a system paste button. The user's tap grants pasteboard access,// so iOS shows no paste prompt.LinkSensePasteButton(onResolve: { url in if let url = url { router.handle(url) }}) // Or from your own "paste your invite link" field:LinkSense.shared.submitPastedLink(text) { url in if let url = url { router.handle(url) }}Link CRUD
The SDK exposes createLink(options:), getLink(id:), updateLink(_:options:), and deleteLink(_:). Each takes a completion that receives a Result on the main queue; the methods themselves can be called from any queue.
LinkSense.shared.createLink( options: CreateLinkOptions( name: "Summer sale", desktopUrl: URL(string: "https://example.com/sale"), iosFallbackUrl: URL(string: "https://apps.apple.com/app/id123456789") )) { result in switch result { case .success(let link): print("Created: \(link.fullUrl)") case .failure(let error): print("Failed: \(error)") }}UpdateLinkOptions fields are FieldUpdate<T>: .unchanged (omit the field), .set(value) (send a new value), or .clear (null it server-side). Links you read back expose their custom data as link.metadata ([String: LinkMetadataValue]?). name, tags and iosClipboardEnabled are RequiredFieldUpdate<T> and cannot be cleared.
Error Handling
CRUD completions receive a Result<T, LinkSenseError> (Result<Void, LinkSenseError> for deleteLink). The LinkSenseError enum maps server error codes to typed cases:
LinkSense.shared.getLink(id: linkId) { result in switch result { case .success(let link): // use link break case .failure(let error): switch error { case .notConfigured: print("Call configure() first") case .network(let underlying): print("Network failure: \(underlying)") case .rateLimited(let retryAfterSeconds): print("Retry after \(retryAfterSeconds ?? 60)s") case .accessDenied(let details): print("Plan limit: \(details.currentUsage ?? 0)/\(details.limit ?? 0) on \(details.plan ?? "?")") case .server(let code, let message, _): print("Server \(code): \(message)") default: print("Other error: \(error)") } }}Common cases: .notConfigured, .network, .unauthorized, .forbiddenCrossScope, .forbiddenField, .invalidInput(fieldErrors:), .notFound, .slugExists, .accessDenied(AccessDeniedDetails), .rateLimited(retryAfterSeconds:) (may be nil), .invalidSdkKey, .decodeFailure(message:), .server(code:message:status:).
.accessDenied is raised when your plan blocks the call — createLink with no subscription or at the link limit — or when the SDK key isn't allowed on this platform. Its AccessDeniedDetails carries serverMessage, upgradeRequired (false when the server sends no details) and the optional plan, currentUsage and limit. Server codes without a dedicated case arrive as .server with the code string.
Example & Resources
The iOS SDK repository ships with a SwiftUI sample app demonstrating configuration, deferred deep link handling, Universal Link forwarding, and link CRUD.