I’m using the new StoreKit 2 APIs in my production app that sells a non-consumable iap. I’ve tested restoring purchases with a StorekitConfiguration in development, along with my own personal Apple ID in production and it works.
The problem is that I’m getting lots of users reporting that restore purchase does’t work on a consistent basis. So my question is, is there something in my production code that is wrong or broken? Or is this a common problem with end users themselves and not my app? My app used the old version of store kit previously, so could that cause this issue?
I always recommend they make sure they’re signed in with the same Apple ID they purchased the app with. Sometimes recommending the user to quit and relaunch the app, or restart there computer fixes the issue. I’ve gotten multiple reports that the only fix was completely deleting then reinstalling the app. And there’s a good portion which non of the above work.
Here’s the code that handles restoring purchases:
/// Attempts to restore any purchases by the user.
/// This is called by the restore purchase button
public func restorePurchase() {
Task {
try? await AppStore.sync()
await updateActiveProducts()
}
}
/// Updates the status of which products have been purchased/are an active subscription
@MainActor public func updateActiveProducts() async {
var purchasedIds: [String] = []
// Iterate through all of the user's purchased products.
for await result in Transaction.currentEntitlements {
do {
let transaction = try checkVerified(result)
// Has the App Store revoked this transaction?
// If it is upgraded do nothing, there is an active transaction for a higher level of service
if transaction.revocationDate != nil || transaction.isUpgraded {
continue
}
// Check if the subscription is expired
if let expirationDate = transaction.expirationDate, expirationDate < Date() {
continue
}
if transaction.productType == .nonConsumable || transaction.productType == .autoRenewable {
purchasedIds.append(transaction.productID)
}
} catch {
// Transaction not verified, don't do anything
}
}
// This is a published property which unlocks the features of the app
self.purchasedIdentifiers = purchasedIds
}
Any advice would be appreciated!