StoreKit 2 - latest transaction for a subscription is not the latest one at launch when app is not running

When dealing with auto-renewable subscriptions, there are multiple ways to access the latest transaction. We can access it when a purchase is made, or we can request the latest transaction for a given productID at a later time. To do so, we can use Transaction.latest(for:), access the transaction history using Transaction.all, get the currentEntitlements, or use the array of Product.SubscriptionInfo.Statusthan contains the latest transaction for a subscription group. It's also necessary to listen to transactions when the app is running using the AsyncSequenceTransaction.updates`.

In my app (and also in the SKDemo project from Apple), when I want to access the latest transaction as soon as the app is launched, it's missing the transactions that renewed or happened while the app was not running. I tried using the different methods mentioned above but they never give me the latest transaction, always the latest transaction while the app was running before I killed it. I have to wait for a new renewal event to receive the latest transaction in the Transaction.updates listener, which is not good. For example, when I set the Subscription Renewal Rate to Monthly Renewal Every 30 seconds, and I quit the app when the latest transactionId is 100, I wait for 5 minutes, I expect to see the transactionId 110 but I see 100. In the real life, it means that if the app is not running when a monthly or annual subscription renews, I have to wait weeks or months to receive the missing transaction. I thought that the Transaction.updates listener would be called at launch with all the transactions that occurred while the app was not running.

Is that a bug in Xcode or have I misunderstood something? How can I access the real latest transaction that happened when the app was not running at launch? I need to access that to know what the user has access to. I think the transaction management panel from Xcode displays all the transactions, even the one when the app was not running.

PS: I'm using Xcode 13.2.1 and iOS 15.0 (simulator). Transaction.updates is not working on iOS 15.2 (my device, or simulator) from what I've seen so far.

Your assumption sounds correct. I would also expect the latest to be “110” in your example. And your testing in Xcode, have you observed this same behavior in sandbox? Please do file a ticket and note it in this thread. We will check on this. FeedbackAssistant.Apple.com

Thanks for your answer.

I’m observing the same behaviour in the sandbox environment. Here are the steps I've done if that helps:

  1. I created a Sandbox account in App Store Connect: I cleared the Purchase History for this tester and set the Subscription Renewal Rate to Monthly Renewal Every 3 Minutes.
  2. I created a fake App in App Store Connect.
  3. I configured a subscription group in App Store Connect for this fake app and added a monthly subscription to this subscription group (this monthly subscription is in Ready To Submit stage after I added enough meta data).
  4. I run the app without using the Xcode config file: the product added to the app on App Store Connect is correctly loaded by the app and I can subscribe to it using the sandbox account on a real device.
  5. I leave the app opened and I receive the transactions when the app is running.
  6. I hard quit the app and wait enough time for virtual renewals to normally be created (for example I wait 30 minutes, which should have renewed the app 10 times based on the Sandbox tester account setup for subscription renewal rate).
  7. I launch the app again and fetch the last transaction for this subscription: it's still the one downloaded 30 minutes ago, before the app was quitted.

I fear the behavior is the same in a production environment so I fear I missed anything and don’t want to ship not working subscription management in my app.

Feedback sent: FB9825000

Thanks for explaining that Transaction.updates does not work with iOS 15.2—I spent the past week troubleshooting this issue under iOS 15.2, and switching to iOS 15.0 solves the problem. I'm using Xcode 13.2.1.

I suspect this too could be related to incorrect cache assumptions made by StoreKit2.

https://developer.apple.com/forums/thread/690890?answerId=705952022#705952022

StoreKit 2 - latest transaction for a subscription is not the latest one at launch when app is not running
 
 
Q