A lightweight wrapper for StoreKit2 that makes implementing in-app purchases simple.
- Fast Integration - Set up StoreKit in minutes, not days
- Seamless Offline Support - Robust local storage ensures purchases work even without internet
- Intelligent Connection Management - Automatically handles transitions between online and offline states of the Store
- Focused Simplicity - Currently only available for non-consumable IAPs (with consumables and subscriptions coming soon)
- Security - Added Receipt Validation
dependencies: [
.package(url: "https://github.com/nicolaischneider/storekitthekit.git", from: "1.0.0")
]
Add the ollowing line to your Podfile
:
pod 'StoreKitTheKit'
Then run pod install
and open your .xcworkspace
.
PurchasableManager.shared.register(purchasableItems: [
Purchasable(bundleId: "com.example.premium", type: .nonConsumable)
])
await StoreKitTheKit.shared.begin()
let result = await StoreKitTheKit.shared.purchaseElement(element: premiumItem)
let isPremium = StoreKitTheKit.shared.elementWasPurchased(element: premiumItem)
await StoreKitTheKit.shared.restorePurchases()
In SwiftUI
// Handle the updated store state
.onReceive(StoreKitTheKit.shared.$storeState) { state in
switch state {
case .available:
print("store is accessible")
case .unavailable:
print("store is unaccessible")
case .checking:
print("connecting to store")
}
}
// Handling of updated locally stored purchases (eg because of reconnection to internet
.onReceive(StoreKitTheKit.shared.$purchaseDataChangedAfterGettingBackOnline) { changed in
if changed {
print("locally stored purchases have been updated.")
}
}
In UIKit:
// Subscribe at view start to get udpates
func subscribe() {
// check state for store
StoreManager.shared.$storeState
.receive(on: DispatchQueue.main)
.sink { [weak self] state in
// Handle the updated store state
}
.store(in: &cancellables)
StoreManager.shared.$purchaseDataChanged
.receive(on: DispatchQueue.main)
.sink { [weak self] changed in
guard let self = self else { return }
if changed {
// Handling of updated locally stored purchases (eg because of reconnection to internet
}
}
.store(in: &cancellables)
}
// Get price for an item
let price = StoreKitTheKit.shared.getPriceFormatted(for: item)
// get total price of multiple items
let totalPrice = StoreKitTheKit.shared.getPriceFormatted(for: [item1, item2])
// Compare prices
let (savings, percentage) = StoreKitTheKit.shared.comparePrice(
for: [item1, item2], with: item3
)
Check out the example app to see a basic implementation.