iOS SDK
Add subscriptions to an iOS app in ~5 minutes. Metera verifies every App Store purchase server-side and tracks who has access to what.
Requirements: iOS 15+ / macOS 12+, Swift 5.9+, StoreKit 2.
1. Add the package
Swift Package Manager — in your Package.swift:
.package(url: "https://github.com/pytronhq/metera-ios-sdk.git", from: "0.1.0")…and add MeteraSDK to your target. In Xcode: File ▸ Add Package Dependencies.
2. Configure at launch
import MeteraSDK
MeteraClient.shared.configure(
apiKey: "app_xxx",
appUserId: nil, // nil → anonymous user
serverURL: "https://your-metera-deployment.example.com"
)Omit appUserId to start anonymous — the SDK generates and persists an ID, and you can promote it later with logIn.
3. Show a paywall
let offerings = try await MeteraClient.shared.getOfferings()
guard let offering = offerings.current else { return }
for package in offering.packages {
// Render package.displayName, look up price via StoreKit if you want it.
}Offerings are configured in the dashboard — you change the paywall without shipping an app update.
4. Purchase
do {
let info = try await MeteraClient.shared.purchase(package)
if info.isActive("pro") { /* unlock */ }
} catch MeteraError.purchaseCancelled {
// user backed out — no-op
}purchase runs the StoreKit 2 flow, sends the transaction to Metera for authoritative server-side verification, and returns fresh CustomerInfo.
5. Gate features
let info = try await MeteraClient.shared.getCustomerInfo()
if info.isActive("pro") {
// pro features
} else {
// show upgrade prompt
}getCustomerInfo() fetches from the backend; cachedCustomerInfo() returns the last value with no network call — good for a launch-time gate.
6. Restore purchases
Wire a "Restore Purchases" button to try await MeteraClient.shared.restorePurchases(). It re-syncs every transaction Apple still considers valid.
7. Identity
// On login — merges the anonymous user into the real account:
try await MeteraClient.shared.logIn("user@example.com")
// On logout — starts a fresh anonymous user:
try await MeteraClient.shared.logOut()8. React to renewals & refunds
The SDK observes StoreKit Transaction.updates, so renewals and refunds that happen while the app runs sync automatically:
Task {
for await info in await MeteraClient.shared.customerInfoUpdates() {
updateUI(proActive: info.isActive("pro"))
}
}Notes
- The Metera app must have App Store Server API credentials configured in the dashboard, and its numeric Apple App ID set, for verification to work.
appAccountTokenis attached to every purchase automatically, so Apple server notifications can be attributed to the user.- Prefer the raw HTTP contract? See the REST API.