StoreKitMadeEasy is a modern, lightweight, production-grade In-App Purchase and Subscription framework for Apple platforms (iOS, macOS, watchOS, tvOS) built from the ground up on Apple's StoreKit 2.
It eliminates the tedious boilerplate of StoreKit 2 while giving you complete reliability: automatic background transaction loops, cryptographic JWS receipt verification, real-time free trial & introductory offer eligibility checking, native refund & subscription management sheets, and offline SwiftUI preview mocking.
Implementing StoreKit 2 correctly requires handling several complex workflows:
- Background Transaction Streams: Listening continuously to
Transaction.updatesso renewals, family shares, and parental approvals ("Ask to Buy") are never dropped. - Cryptographic JWS Verification: Verifying that transactions are signed by Apple without relying on third-party servers.
- Introductory Offers & Free Trials: Accurately detecting if a user has already consumed their free trial or introductory discount.
- Subscription Lifecycle States: Differentiating between active subscribers, users in billing retry, users in Apple's grace period, and revoked purchases.
- System Sheet Integrations: Invoking Apple's native refund request sheets and manage subscriptions windows.
StoreKitMadeEasy bundles all of this into a clean, modern Swift API.
- In Xcode, navigate to File > Add Package Dependencies...
- In the search bar, paste:
https://github.com/zoraizbutt/StoreKitMadeEasy.git - Set the Dependency Rule to Up to Next Major Version starting at
1.0.0. - Click Add Package.
Add StoreKitMadeEasy to your Package.swift dependencies:
dependencies: [
.package(url: "https://github.com/zoraizbutt/StoreKitMadeEasy.git", from: "1.0.0")
]Add the pod to your Podfile:
pod 'StoreKitMadeEasy', '~> 1.0.0'Then install:
pod installStart StoreKitMadeEasy as early as possible in your app lifecycle (e.g. in your SwiftUI @main App or UIKit AppDelegate). This immediately spins up the background transaction listener:
import SwiftUI
import StoreKitMadeEasy
@main
struct MyApp: App {
init() {
// Configure your product IDs and start background listeners
StoreKitMadeEasy.shared.start(productIDs: [
"com.app.monthly",
"com.app.yearly",
"com.app.lifetime",
"com.app.coins100"
])
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}No async calls needed to check accessβentitlements are tracked in real-time in an observable @Published dictionary:
import StoreKitMadeEasy
// Check if a specific feature or product is unlocked
if StoreKitMadeEasy.shared.hasActiveEntitlement("com.app.yearly") {
// Grant Pro feature access
}
// Or check if user has ANY active subscription
if StoreKitMadeEasy.shared.hasAnyActiveSubscription {
// Grant subscription benefits
}Purchasing handles transaction execution, cryptographic JWS verification, entitlement unlocking, and calling transaction.finish() automatically:
do {
let result = try await StoreKitMadeEasy.shared.purchase(id: "com.app.yearly")
switch result {
case .success(let transaction, let entitlement):
print("Purchased successfully: \(transaction.productID)")
print("Active until: \(String(describing: entitlement.expirationDate))")
case .userCancelled:
print("User dismissed purchase sheet.")
case .pending:
print("Transaction is pending (e.g., Ask to Buy parental approval or 3D Secure bank authorization).")
}
} catch {
print("Purchase failed with error: \(error.localizedDescription)")
}StoreKit 2 automatically restores purchases on app launch. However, Apple App Store Review Guidelines require a visible "Restore Purchases" button for users:
do {
try await StoreKitMadeEasy.shared.restorePurchases()
print("Purchases restored successfully!")
} catch {
print("Failed to restore purchases: \(error.localizedDescription)")
}StoreKitMadeEasy includes native sheet presentation helpers:
// 1. Present Apple's native Manage Subscriptions sheet
try await StoreKitMadeEasy.shared.showManageSubscriptions()
// 2. Present Apple's native Refund Request sheet
try await StoreKitMadeEasy.shared.beginRefundRequest(for: transactionID)
// 3. Present Offer Code redemption sheet (iOS)
StoreKitMadeEasy.shared.presentOfferCodeRedemptionSheet()Or use the provided SwiftUI view modifiers:
struct SettingsView: View {
@State private var showManageSubscriptions = false
@State private var showOfferCodeSheet = false
var body: some View {
List {
Button("Manage Subscriptions") { showManageSubscriptions = true }
Button("Redeem Code") { showOfferCodeSheet = true }
}
.manageSubscriptionsSheet(isPresented: $showManageSubscriptions)
.offerCodeRedemptionSheet(isPresented: $showOfferCodeSheet)
}
}StoreKitMadeEasy includes a pre-built PaywallViewModel that binds directly to the store and handles loading, product selection, trial badges, and purchase states:
import SwiftUI
import StoreKitMadeEasy
struct PaywallView: View {
@StateObject private var viewModel = PaywallViewModel()
@Environment(\.dismiss) private var dismiss
var body: some View {
VStack(spacing: 20) {
// Header
VStack(spacing: 8) {
Text("Unlock Premium")
.font(.largeTitle.bold())
Text("Get unlimited access to all features")
.font(.subheadline)
.foregroundColor(.secondary)
}
.padding(.top)
// Product Cards
VStack(spacing: 12) {
ForEach(viewModel.products) { product in
Button {
viewModel.select(product)
} label: {
HStack {
VStack(alignment: .leading, spacing: 4) {
Text(product.displayName)
.font(.headline)
// Free trial badge (only displayed if user is eligible!)
if let trial = product.freeTrialDescription, product.isEligibleForIntroOffer {
Text(trial)
.font(.caption.bold())
.foregroundColor(.green)
}
}
Spacer()
VStack(alignment: .trailing) {
Text(product.displayPrice)
.font(.headline)
if let period = product.periodDescription {
Text("per \(period)")
.font(.caption)
.foregroundColor(.secondary)
}
}
}
.padding()
.background(
RoundedRectangle(cornerRadius: 12)
.stroke(viewModel.selectedProduct?.id == product.id ? Color.blue : Color.gray.opacity(0.3), lineWidth: 2)
)
}
.buttonStyle(.plain)
}
}
.padding(.horizontal)
Spacer()
// Error display
if let error = viewModel.errorMessage {
Text(error)
.font(.caption)
.foregroundColor(.red)
}
// Purchase Button
Button {
Task {
await viewModel.purchaseSelected()
if viewModel.purchaseSuccess {
dismiss()
}
}
} label: {
HStack {
if viewModel.isPurchasing {
ProgressView()
.tint(.white)
} else {
Text("Continue")
.bold()
}
}
.frame(maxWidth: .infinity)
.frame(height: 50)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(12)
}
.disabled(viewModel.isPurchasing)
.padding(.horizontal)
// Restore & Terms
HStack(spacing: 16) {
Button("Restore Purchases") {
Task { await viewModel.restore() }
}
Text("β’")
Button("Terms of Service") {}
Text("β’")
Button("Privacy Policy") {}
}
.font(.caption)
.foregroundColor(.secondary)
.padding(.bottom)
}
}
}StoreKitMadeEasy comes with a bundled Xcode StoreKit configuration file located in:
Configuration/Products.storekit
- In Xcode, go to Product > Scheme > Edit Scheme...
- In the left panel, select Run, then open the Options tab.
- Under StoreKit Configuration, select
Products.storekit. - Run your app in the simulator.
- In Xcode's debug area, use Debug > StoreKit > Manage Transactions to:
- Speed up subscription renewals (e.g. 1 month renewing every 30 seconds).
- Test free trial expiration and conversion to paid.
- Simulate card declines, billing retries, and refunds.
- Simulate Ask to Buy parental approval workflows.
- Go to App Store Connect > Users and Access > Sandbox Testers.
- Create a new sandbox tester account.
- On your physical iPhone / iPad, go to Settings > App Store > Sandbox Account and sign in.
- Run your app in Debug mode with your real App Store product IDs.
Preview your paywalls without making any network calls:
#Preview {
PaywallView()
// Powered by MockStoreKitMadeEasy with simulated trial periods
}StoreKitMadeEasy categorizes subscription states accurately:
| State | Description | Access Granted? |
|---|---|---|
.active |
Normal active subscription | β Yes |
.inTrial |
User is within free trial period | β Yes |
.inGracePeriod |
Billing failed, but within Apple's Grace Period | β Yes |
.inBillingRetry |
Billing failed, Apple is retrying payment | β No |
.expired |
Subscription ended and was not renewed | β No |
.revoked |
Apple refunded or revoked access | β No |
Contributions, issues, and feature requests are welcome! Feel free to open an issue or submit a pull request on GitHub.
StoreKitMadeEasy is available under the MIT License. See the LICENSE file for more info.