Hi, I’m running into a persistent error while implementing StoreKit 2 renewable subscriptions in my SwiftUI app.
Context
- I have a two-screen flow:
- Screen 1: user selects a subscription plan (monthly / yearly).
- Screen 2: user fills out personal information and taps Subscribe that triggers the purchase function.
- On first launch or the first couple of purchases (on both Storekit's local and Sandbox testing), everything works fine. The App Store popup appears, the purchase goes through, and I get the transaction result.
- But after a few runs (3rd or 4th purchase attempt onward), my app crashes the moment the App Store purchase popup appears.
Error Logs
When the crash happens, the console shows:
`unable to close due to unfinalized statements or unfinished backups
BUG IN CLIENT OF libsqlite3.dylib: database integrity compromised by API violation: vnode unlinked while in use: /private/var/mobile/Containers/Data/Application/D8D97A11-DF06-4EF2-AC55-138C4739A167/Library/d6d2e85a60f0480c4c17834eeb827a14_MPDB.sqlite
invalidated open fd: 21 (0x11)
BUG IN CLIENT OF libsqlite3.dylib: database integrity compromised by API violation: vnode unlinked while in use: ...`
Observations
- The error only shows after some time maybe due to multiple transactions and switching between plans for the same user, not on the very first purchases.
- If I land on the purchase screen immediately after app launch, the purchase works. But if I wait a while before navigating to the purchase screen, the popup causes the app to crash.
- I’m not using Core Data or my own SQLite database at all - so I assume this DB (MPDB.sqlite) is StoreKit’s internal persistence.
Things I’ve tried so far
- Cleaning StoreKit caches:
rm -rf ~/Library/Developer/CoreSimulator/Devices/*/data/Container s/Data/Application/*/Library/Caches/storekit
- Rebuilding from scratch, cleaning build folder.
- Switching between sandbox accounts, signing out/in again.
- Added await transaction.finish() after verified purchases.
- Added cleanup for unfinished transactions at app launch:
for await result in Transaction.unfinished {
if case .verified(let transaction) = result {
await transaction.finish()
}
}
- Tried both StoreKit Configuration file and sandbox environment but issue persists in both.
Questions
- Is this error StoreKit-specific (internal SQLite DB corruption) or something wrong in my implementation?
- Why would it only appear after a few runs / with a delay before navigating to the purchase screen?
- Am I missing something else in handling StoreKit 2 transactions?
Screenshots of the errors are attached for context.
Any insights would be really appreciated...I’m stuck because I can’t tell if this is an Apple bug with StoreKit 2 or something I’ve overlooked in my code.
Specs: Xcode 16.4 Build version 16F6 iOS version: 18.6.2