iOS SDK
The iOS SDK (TolinkuSDK) provides Universal Link handling, deferred deep linking, event tracking, referrals, and in-app messages for iOS 15+ and macOS 13+.
Installation
Section titled “Installation”Add the SDK via Swift Package Manager in Xcode:
- Go to File > Add Package Dependencies.
- Enter the repository URL:
https://github.com/tolinku/ios-sdk - Select the latest version and add the
TolinkuSDKlibrary to your target.
Configure the SDK as early as possible in your app lifecycle:
import TolinkuSDK
// In your App init or AppDelegate:do { let tolinku = try Tolinku.configure(apiKey: "tolk_pub_your_key")} catch { print("Tolinku configuration failed: \(error)")}Optionally specify a custom base URL:
try Tolinku.configure( apiKey: "tolk_pub_your_key", baseURL: "https://your-app.tolinku.com")Access the shared instance anywhere in your app:
// Optional access (nil before configure)Tolinku.shared?.track("custom.screen_view")
// Throwing access (throws TolinkuError.notConfigured)let tolinku = try Tolinku.requireShared()User identification
Section titled “User identification”Tolinku.shared?.setUserId("user_123")
// Clear on logoutTolinku.shared?.setUserId(nil)Event tracking
Section titled “Event tracking”// Simple eventawait Tolinku.shared?.track("custom.app_open")
// Event with propertiesawait Tolinku.shared?.track("custom.purchase", properties: [ "amount": .string("29.99"), "currency": .string("USD")])
// Force flushawait Tolinku.shared?.flush()Events are batched (10 events or 5-second timer) and auto-flushed when the app enters the background.
Ecommerce tracking
Section titled “Ecommerce tracking”Track purchases, cart activity, and product events via ecommerce:
let tolinku = try Tolinku.requireShared()tolinku.setUserId("user_123")
// Track a purchaseawait tolinku.ecommerce.purchase( transactionId: "order_456", revenue: 49.99, currency: "USD", items: [TolinkuItem(itemId: "sku_1", itemName: "T-Shirt", price: 24.99, quantity: 2)])
// Track product views and cart eventsawait tolinku.ecommerce.viewItem( items: [TolinkuItem(itemId: "sku_1", itemName: "T-Shirt", price: 24.99)])await tolinku.ecommerce.addToCart( items: [TolinkuItem(itemId: "sku_1", quantity: 1)])await tolinku.ecommerce.beginCheckout()
// Search and ratingsawait tolinku.ecommerce.search(searchTerm: "shoes")await tolinku.ecommerce.rate(itemId: "sku_1", rating: 4.5, maxRating: 5)
// Force flushawait tolinku.ecommerce.flush()Ecommerce events are batched (10 events or 5-second timer) and auto-flushed when the app enters the background. The SDK manages cart IDs automatically via UserDefaults, clearing them after purchase. All money values use Swift Decimal for precision.
Handling Universal Links
Section titled “Handling Universal Links”Parse incoming Universal Links using the static helper:
// UIKit AppDelegatefunc application( _ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { guard userActivity.activityType == NSUserActivityTypeBrowsingWeb, let url = userActivity.webpageURL, let result = Tolinku.handleUniversalLink(url) else { return false }
// result.path - e.g. "/merchant/abc123" // result.queryItems - any query parameters navigateToDeepLink(path: result.path) return true}For SwiftUI:
@mainstruct MyApp: App { init() { try? Tolinku.configure(apiKey: "tolk_pub_your_key") }
var body: some Scene { WindowGroup { ContentView() .onOpenURL { url in if let result = Tolinku.handleUniversalLink(url) { // Navigate to result.path } } } }}Deferred deep linking
Section titled “Deferred deep linking”Claim the original link destination after the user installs your app:
// Signal-based claiming (recommended for iOS)if let link = try await Tolinku.shared?.deferred.claimBySignals( appspaceId: "your_appspace_id") { // Navigate to link.deep_link_path}The SDK automatically collects timezone, language, and screen dimensions for fingerprint matching.
Token-based claiming is also available (for cases where you have a referrer token):
if let link = try await Tolinku.shared?.deferred.claimByToken("token") { // Navigate to link.deep_link_path}Referrals
Section titled “Referrals”let referrals = Tolinku.shared!.referrals
// Create a referral codelet result = try await referrals.create(userId: "user_123", userName: "Jane")print(result.referral_code) // "ABC123"print(result.referral_url) // "https://myapp.tolinku.com/ref/ABC123"
// Look up a referrallet info = try await referrals.get(code: "ABC123")
// Link a referred user (status stays pending until reward milestone is reached)try await referrals.complete(code: "ABC123", referredUserId: "user_456")
// Update milestone (completes the referral if it matches the reward milestone)try await referrals.milestone(code: "ABC123", milestone: "first_purchase")
// Claim reward (after granting it in your system)try await referrals.claimReward(code: "ABC123")
// Get leaderboardlet leaders = try await referrals.leaderboard(limit: 10)In-app messages
Section titled “In-app messages”Fetch and display messages:
// UIKit: show highest-priority messageawait Tolinku.shared?.messages.show( trigger: "on_open", from: viewController, onAction: { action in // Handle CTA action URL }, onDismiss: { // Message dismissed })Messages are rendered in a WKWebView dialog.
Shutdown
Section titled “Shutdown”Clean up when the app terminates or you need to reconfigure:
await Tolinku.shutdown()