horse revenue Docs

SDK reference

Horse iOS SDK

The Horse iOS SDK is the open-source HorseKit Swift package. It sells through StoreKit 2, sends every transaction to Horse, and keeps the customer's access cached on the device.

Packagegithub.com/HorseRevenue/horsekit-ios
Current version2.0.0 (changelog)
PlatformsiOS 15, iPadOS 15, macOS 12, tvOS 15, watchOS 8, visionOS 1 and later
LicenceMIT
Full APIAPI reference, generated from the source

#Install

Package.swift
.package(url: "https://github.com/HorseRevenue/horsekit-ios.git", from: "2.0.0")

In Xcode: File → Add Package Dependencies… → https://github.com/HorseRevenue/horsekit-ios, Up to Next Major Version from 2.0.0. The tutorial walks through it.

#Libraries

LibraryContainsLinks
HorseKitPurchases, entitlements, offerings, remote config, experiments, access codes, analyticsStoreKit only
HorseKitUIPaywalls designed in the dashboard, drawn natively (PaywallView)SwiftUI, AVFoundation
HorseKitSearchAdsApple Search Ads attributionAdServices, with no tracking prompt
HorseKitAttributionFor apps that run ads: IDFA, ATT status, ad-network ids, plus HorseKitSearchAdsAdSupport, AppTrackingTransparency, AdServices

Most apps add HorseKit and HorseKitUI, and import each one where they use it. HorseKitAttribution re-exports HorseKit and HorseKitSearchAds. The other libraries don't re-export anything, so import HorseKit alongside them.

#Configuration

Horse.configure(with: .init(
    apiKey: "pk_…",
    appUserID: nil,
    baseURL: URL(string: "https://tally-api-755619271848.us-central1.run.app")!,
    logLevel: .warn,
    finishTransactions: true,
    restorePolicy: .onRestore,
    startPolicy: .automatic,
    analytics: .on,
    screenTracking: .manual
))
OptionDefaultWhat it does
apiKeyThe app's SDK key from SDK & settings. Safe to ship in the binary.
appUserIDnilYour own user id, when the app has accounts. nil gives the install an anonymous id. You can also call logIn later.
baseURLHorse's API address, as shown above.
logLevel.warnUse .debug while integrating. Logs go to the unified log, subsystem com.horse.sdk. Horse.setLogHandler takes them over.
finishTransactionstrueThe SDK finishes each transaction once Horse has it. Turn it off only if other code finishes them.
restorePolicy.onRestoreWhether purchases the Apple Account already owns unlock this install at launch (.automatic), or only after Restore or syncPurchases(). Purchases made in this install are always recognised at once. See restoring.
startPolicy.automatic.onDemand makes no network call until you ask for something, for a widget or a screensaver.
analytics.onSessions, screens, the paywall funnel and track. .off sends nothing at all.
screenTracking.manual.automatic names UIKit screens by their view controller. SwiftUI uses .horseScreen("…") either way.

Horse.configure(apiKey:appUserID:baseURL:logLevel:restorePolicy:) is a shorthand for the common options.

#What it does by itself

  • Fetches the customer's access at launch and whenever the app returns to the foreground (at most once a minute), and remote config every five minutes.
  • Listens to Transaction.updates for renewals, Ask to Buy approvals, purchases made outside the app and refunds, and sends them to Horse.
  • Works offline. A purchase unlocks at once and reaches Horse when the network is back, and access is read from the cache, then from StoreKit's own verified state.
  • On visionOS, a purchase is confirmed in the scene of the app's key window.

#Privacy

  • The SDK ships no privacy manifest of its own. Your app's PrivacyInfo.xcprivacy must declare the UserDefaults API with reason CA92.1.
  • App Privacy: purchase history and a user id are collected, linked to the person, for app functionality. With HorseKitAttribution and the tracking prompt, the advertising identifier is collected too, only once the person allows tracking.
  • Without HorseKitAttribution, the binary links neither AdSupport nor AppTrackingTransparency, and there's nothing about tracking to declare.

#Versioning

The SDK uses semantic versioning. A patch fixes, a minor adds API and old code keeps compiling, and a major can break things, with the changelog saying what and how to migrate. With Up to Next Major Version, minors arrive on File → Packages → Update to Latest Package Versions, and a major never arrives by surprise.

#Help

Questions, bugs and feature requests: open an issue on GitHub, or write to info@horserevenue.app.