iOS SDK

Native Swift SDK for iOS applications with deep link handling.

The iOS SDK provides native Swift integration with automatic deep link handling, deferred deep links, and App Clip support.

Installation

CocoaPods

pod 'ReferralEngine', '~> 1.0'

Swift Package Manager

dependencies: [
  .package(url: "https://github.com/referral-engine/ios-sdk.git", from: "1.0.0")
]

Initialization

Initialize the SDK in your AppDelegate:

import ReferralEngine

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
  func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    
    ReferralEngine.configure(
      apiKey: "your_api_key",
      options: REOptions(
        enableDeepLinks: true,
        enableDeferredDeepLinks: true
      )
    )
    
    return true
  }
}

Deep Link Handling

Handle Universal Links in your SceneDelegate:

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
  guard let url = userActivity.webpageURL else { return }
  
  ReferralEngine.shared.handleDeepLink(url) { result in
    switch result {
    case .success(let referral):
      print("Referred by: \(referral.referrerUserId)")
      
    case .failure(let error):
      print("Not a referral link or error: \(error)")
    }
  }
}

Generating Links

ReferralEngine.shared.createLink(
  userId: "user_123",
  campaignId: "camp_abc"
) { result in
  switch result {
  case .success(let link):
    let activityVC = UIActivityViewController(
      activityItems: [link.url],
      applicationActivities: nil
    )
    present(activityVC, animated: true)
    
  case .failure(let error):
    print("Error: \(error)")
  }
}

Tracking Events

ReferralEngine.shared.trackEvent(
  name: "signup",
  userId: "new_user_456",
  properties: ["plan": "premium"]
)

ReferralEngine.shared.trackEvent(
  name: "purchase",
  userId: "new_user_456",
  properties: [
    "amount": 99.99,
    "currency": "USD"
  ]
)
Enable App Tracking Transparency for best attribution accuracy on iOS 14.5+.