I have two iPhones I use for testing my app.
On Device A:
NSLog(@"Unfinished Transactions: [%i]", [[SKPaymentQueue defaultQueue].transactions count]);
Which outputs: “Unfinished Transactions: [0]”
When when I do a:
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions]
the function
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
gets called with 17 items in the transactions array, each flagged as RESTORED. So, I loop over the set and call [[SKPaymentQueue defaultQueue] finishTransaction: transaction] on each.
After processing each item, (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue is called, and [[queue transactions] count] is equal to 4, not 17, which is something of a surprise.
If I re-run [[SKPaymentQueue defaultQueue] restoreCompletedTransactions] on this device, I repeatedly get the same result – despite having told each transaction I want it removed from the queue, updatedTransactions gets called with 17 items to process.
On device B,
$NSLog(@"Unfinished Transactions: [%i]", [[SKPaymentQueue defaultQueue].transactions count]);
Still outputs “Unfinished Transactions: [0]”
When I run
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions]
, the function
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
NEVER gets called. Eventually
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
is called, with
[[queue transactions] count]
equal to 0.
What could be causing this? It’s almost like the payment queue is linked to the device ID, not the Test Account Apple ID. Also, please forgive the terrible formatting of this question, I’m still getting used to StackOverflow. 🙂
This is a sandbox environment bug. I have had exactly the same issue that the
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactionswas never called. Only the
paymentQueueRestoreCompletedTransactionsFinishedarrived after the call torestoreCompletedTransactions.I have checked it with an Apple engineer. He confirmed that my code is indeed correct and I should receive the
updatedTransactionscall. He said that the fact this is not happening in the sandbox environment is apparently a bug (he was not surprised about it at all).Honestly there is not much you can do about it. After he confirmed my code is correct I took the risk and released the App. It all works as expected with the real iTunes Connect server.
So your best (maybe only) bet is to make sure you have it all set up as expected and go ahead and test it against the live server. Good luck! It worked for me.