I’m operating right into a persistent error whereas implementing StoreKit 2 renewable subscriptions in my SwiftUI app.
Context
I’ve a two-screen circulate:
- Display screen 1: consumer selects a subscription plan (month-to-month / yearly).
- Display screen 2: consumer fills out private info and faucets Subscribe that triggers the acquisition perform.
On first launch or the primary couple of purchases (on each StoreKit’s native testing and Sandbox testing), every little thing works advantageous. The App Retailer popup seems, the acquisition goes by way of, and I get the transaction consequence.
However after a number of runs (third or 4th buy try onward), my app crashes the second the App Retailer buy popup seems.
Error Logs
When the crash occurs, the console exhibits:
unable to shut resulting from unfinalized statements or unfinished backups
BUG IN CLIENT OF libsqlite3.dylib: database integrity compromised by API violation: vnode unlinked whereas in use: /non-public/var/cell/Containers/Information/Software/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 whereas in use: ...
Observations
- The error solely exhibits after a while, possibly resulting from a number of transactions and switching between plans for a similar consumer, not on the very first purchases.
- If I land on the acquisition display screen instantly after app launch, the acquisition works. But when I wait some time earlier than navigating to the acquisition display screen, the popup causes the app to crash.
- I’m not utilizing Core Information or my very own SQLite database in any respect, so I assume this DB (MPDB.sqlite) is StoreKit’s inner persistence.
Issues I’ve tried up to now
- Cleansing StoreKit caches:
rm -rf ~/Library/Developer/CoreSimulator/Units/<device_id>/knowledge/Containers/Information/Software/<app_id>/Library/Caches/storekit
- Rebuilding from scratch, cleansing construct folder.
- Switching between sandbox accounts, signing out/in once more.
- Added
await transaction.end()
after verified purchases. - Added cleanup for unfinished transactions at app launch:
for await end in Transaction.unfinished {
if case .verified(let transaction) = consequence {
await transaction.end()
}
}
- Tried each StoreKit Configuration file and Sandbox setting, however challenge persists in each.
Query
- Is that this error StoreKit-specific (inner SQLite DB corruption) or one thing unsuitable in my implementation?
- Why would it not solely seem after a number of runs / with a delay earlier than navigating to the acquisition display screen?
- Am I lacking one thing else in dealing with StoreKit 2 transactions?
Screenshots of the errors are hooked up for context.
Any insights can be actually appreciated… I’m caught as a result of I can’t inform if that is an Apple bug with StoreKit 2 or one thing I’ve ignored in my code.
Specs
- Xcode: 16.4
- Construct model: 16F6
- iOS model: 18.6.2
- Record merchandise