I am trying to implement an auto-renewable subscription for the first time and I'm having so much trouble with erratic behaviour from the Sandbox environment that at this point, I'm not sure if the behaviour I'm expecting is correct or not. I can't seem to get two tests in a row to behave the same way.
I'm registering an SKPaymentTransactionObserver observer ASAP on startup, I can create a subscription and it arrives properly (after several retries but lets ignore that for the moment), then I wait 5-6 minutes expecting that some background process will add a renewal transaction to my SKPaymentQueue before the expiry time of the subscription.
If I then restart my app, sometimes (but not always), the renewal transaction will be delivered to my SKPaymentTransactionObserver after the restart and the subscription then works correctly until the next expiry.
At that point, restoring purchases usually works, but that's not been reliable either because of frequent errors just connecting to the App Store.
So what's the story here? Have I missed some step somewhere to get those renewals delivered to the device?
Your app will get hit with a call to updatedTransactions when it enters the foreground as long as you left a transaction observer in place. If you removed the transaction observer (I do that) then your app will be hit with a call to updatedTransactions when it adds a transaction observer. I do not know whether there will be a call to updatedTransactions if the app is in the foreground when a renewal transaction is approved. Certainly it is called when it is in the foreground and there is an original purchase.
In the edge case of that renewal transaction being approved while the app is in the foreground - should it not result in a call to updatedTransactions - you can ignore the discrepency between Apple's records and the app's records. The discrepancy will continue after the app enters background and will be aligned the next time the app enters foreground.