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.
| Package | github.com/HorseRevenue/horsekit-ios |
| Current version | 2.0.0 (changelog) |
| Platforms | iOS 15, iPadOS 15, macOS 12, tvOS 15, watchOS 8, visionOS 1 and later |
| Licence | MIT |
| Full API | API reference, generated from the source |
#Install
.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
| Library | Contains | Links |
|---|---|---|
HorseKit | Purchases, entitlements, offerings, remote config, experiments, access codes, analytics | StoreKit only |
HorseKitUI | Paywalls designed in the dashboard, drawn natively (PaywallView) | SwiftUI, AVFoundation |
HorseKitSearchAds | Apple Search Ads attribution | AdServices, with no tracking prompt |
HorseKitAttribution | For apps that run ads: IDFA, ATT status, ad-network ids, plus HorseKitSearchAds | AdSupport, 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
))| Option | Default | What it does |
|---|---|---|
apiKey | The app's SDK key from SDK & settings. Safe to ship in the binary. | |
appUserID | nil | Your own user id, when the app has accounts. nil gives the install an anonymous id. You can also call logIn later. |
baseURL | Horse's API address, as shown above. | |
logLevel | .warn | Use .debug while integrating. Logs go to the unified log, subsystem com.horse.sdk. Horse.setLogHandler takes them over. |
finishTransactions | true | The SDK finishes each transaction once Horse has it. Turn it off only if other code finishes them. |
restorePolicy | .onRestore | Whether 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 | .on | Sessions, 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.updatesfor 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.xcprivacymust declare the UserDefaults API with reasonCA92.1. - App Privacy: purchase history and a user id are collected, linked to the person, for app functionality. With
HorseKitAttributionand 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.