Mobile SDK
iOS SDK
Native Swift SDK for click tracking and attribution. Built with Rust and compiled to a Swift Package via UniFFI.
Installation
Add the Swift Package
Download the latest rift-ios-sdk-*.tar.gz from GitHub Releases. Extract it and add the directory as a local Swift package in Xcode:
File → Add Package Dependencies → Add Local and select the extracted ios/ directory.
Import and initialize
You need a publishable key to initialize the SDK.
import RiftSDK
// Initialize once at app launch (e.g., in AppDelegate or @main).
let rift = RiftSdk(publishableKey: "pk_live_YOUR_KEY")
// Or point to a self-hosted instance:
let rift = RiftSdk(publishableKey: "pk_live_YOUR_KEY", baseUrl: "https://api.yourcompany.com")Click Tracking
Record a click
If your app opens Rift links internally (e.g., share sheets), record the click:
do {
let result = try await rift.click(linkId: "summer-sale")
print("Platform: \(result.platform)")
print("Deep link: \(result.iosDeepLink ?? "none")")
} catch {
print("Click error: \(error)")
}Post-Install Attribution
Check clipboard on app launch
When a user clicks a Rift link on iOS, the landing page copies the full link URL to the clipboard. On first launch after install, read the clipboard, extract the link ID, fetch the link data, and report attribution:
func handleDeferredDeepLink() async {
guard let clipboard = UIPasteboard.general.string,
let linkId = parseClipboardLink(text: clipboard) else {
return
}
// Clear clipboard after reading.
UIPasteboard.general.string = ""
// Report attribution.
do {
let _ = try await rift.reportAttribution(
linkId: linkId,
installId: UIDevice.current.identifierForVendor?.uuidString ?? UUID().uuidString,
appVersion: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "unknown"
)
} catch {
print("Attribution error: \(error)")
}
// Fetch link data to navigate.
if let link = try? await Rift.getLink(linkId) {
if let deepLink = link.iosDeepLink {
handleDeepLink(deepLink)
}
}
}parseClipboardLink(text:) helper handles both full URLs (e.g. https://go.yourcompany.com/summer-sale) and the legacy rift:<link_id> format.API Reference
RiftSdk(publishableKey:, baseUrl:)
Constructor. The publishableKey parameter is required. The baseUrl is optional (defaults to https://api.riftl.ink).
Methods
| Method | Returns | Description |
|---|---|---|
| click(linkId) | ClickResult | Records a click and returns link data. |
| reportAttribution(linkId, installId, appVersion) | Bool | Reports an install attribution. |
Free functions
| Function | Description |
|---|---|
| parseClipboardLink(text:) | Extracts link ID from a clipboard URL (e.g. https://go.example.com/summer-sale) or legacy rift:<link_id> format. Returns nil if not found. |