Mobile SDK
iOS SDK
Native Swift SDK for deep linking, attribution, user binding, and conversion tracking. Built with Rust and compiled to a Swift Package via UniFFI. Install ID persists across app reinstalls via the iOS Keychain.
Quick Start
Add the Swift Package
Download the latest rift-ios-sdk-*.tar.gz from GitHub Releases. Extract it and add as a local Swift package in Xcode:
File → Add Package Dependencies → Add Local and select the extracted ios/ directory.
Initialize (one line)
You need a publishable key. The convenience constructor auto-wires Keychain storage and reads the app version from Bundle.main.
import RiftSDK
// One line — Keychain storage, app version, all defaults.
let rift = RiftSdk.create(publishableKey: "pk_live_YOUR_KEY")install_id (UUID) on first launch and stores it in the Keychain. It survives app deletion and reinstallation.Bind the user (one line)
Call setUserId wherever you handle your user session — after signup, login, or session restore. Safe to call on every launch. The SDK handles persistence, sync, and retry.
// Wherever you know the user is signed in:
Task {
try? await rift.setUserId(userId: currentUser.id)
}Track conversions (one line)
Fire a conversion event whenever a user does something worth counting. The SDK reads the bound user_id and POSTs to the Rift API using your publishable key.
// On trade completion, purchase, signup — whatever you're measuring:
try await rift.trackConversion(
conversionType: "trade",
idempotencyKey: orderId,
metadata: ["asset": "ETH", "side": "buy"]
)The server dedupes via idempotencyKey, so retries are safe.
Deferred Deep Linking
One-call deferred deep link (3 lines)
On first launch, check the clipboard for a Rift link. The SDK parses it, reports attribution, and returns the link data for navigation — all in one call.
// On first launch:
if let result = try await rift.checkDeferredDeepLink(
clipboardText: UIPasteboard.general.string
) {
UIPasteboard.general.string = "" // clear after reading
if let deepLink = result.iosDeepLink {
handleDeepLink(deepLink)
}
}Click Tracking
Record a click
If your app opens Rift links internally (e.g., share sheets), record the click:
let result = try await rift.click(linkId: "summer-sale")
print("Platform: \(result.platform)")
print("Deep link: \(result.iosDeepLink ?? "none")")Logout
Call clearUserId() when the user signs out. The install ID is preserved — only the user binding is removed.
try rift.clearUserId()API Reference
Constructors
| Constructor | Description |
|---|---|
| RiftSdk.create(publishableKey:) | Convenience. Auto-wires Keychain storage + app version. Recommended. |
| RiftSdk(config:, storage:) | Full control. Pass custom RiftConfig and RiftStorage implementation. |
Methods
| Method | Returns | Description |
|---|---|---|
| setUserId(userId:) | Void (async throws) | Bind the install to a user. Persists + syncs + retries on next launch. |
| trackConversion(conversionType:, idempotencyKey:, metadata:?) | Void (async throws) | Fire a conversion event. POSTs to the Rift API via publishable key. |
| checkDeferredDeepLink(clipboardText:) | DeferredDeepLinkResult? (async throws) | One-call deferred deep link: parse, attribute, fetch link data. |
| clearUserId() | Void (throws) | Remove stored user binding. Call on logout. |
| installId() | String (throws) | Persistent install UUID. Generates on first call. |
| reportAttributionForLink(linkId:) | Bool (async throws) | Simplified attribution — uses internal install_id + app version. |
| click(linkId:) | ClickResult (async throws) | Record a click and return link data. |
| getLink(linkId:) | GetLinkResult (async throws) | Fetch link data without recording a click. |
Free functions
| Function | Description |
|---|---|
| parseClipboardLink(text:) | Low-level: extracts link ID from a URL. Used internally by checkDeferredDeepLink. |