Problems with using Apple Hosted Content for downloading In-App purchased content

Hi,

I'm experiencing multiple problems when trying to restore In-app purchased contents through Apple Hosted Content. The device I'm using is iPad / OS 14.7.1

Problem A : Crash

  1. Launch the app
  2. call '[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];' to create transactions for the contents. -> This results in 'updatedTransactions' method to be invoked.
  3. In 'updatedTransactions', for each transaction, I call '[[SKPaymentQueue defaultQueue] startDownloads' for the downloads attached to the transaction.
  4. Before the downloads are completed, I finish the transactions by calling '[[SKPaymentQueue defaultQueue] finishTransaction];' for each transaction.
  5. After wating a while, an exception is raised with the message as below and the app crashes with it.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]' terminating with uncaught exception of type NSException

  1. By observing the logs from 'appstored', I believe this exception is raised when the download process in the background is completed. This means although 'finishTransaction' was called for the transaction, the download process for the transaction didn't get terminated.
  2. I found out that this exception doesn't happen if there is no 'updatedDownloads' method implemented in my transaction observer.

Problem B : Multiple download sessions for the same transaction.

  1. Launch the app
  2. call '[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];' to create transactions for the contents. -> This results in 'updatedTransactions' method to be invoked.
  3. In 'updatedTransactions', for each transaction, I call '[[SKPaymentQueue defaultQueue] startDownloads' for the downloads attached to the transaction.
  4. Before the downloads are completed, close the app.
  5. Launch the app again
  6. I observe that 'updatedTransactions' method is invoked with the transactions from the previous run of the app which is expected as 'finishTransaction' was not called for the transactions.
  7. In updatedTransactions method, I call 'startDownloads' for each transaction. This is where I get confused. Obviously, downloads are started for the transactions in the previous run. However, in this run, when 'updatedTransactions' is invoked, the downloads in the transactions has their state as 'waiting'. And if I don't call 'startDownloads' for the transactions, 'updatedDownloads' is not invoked. So, I have no choice but to call 'startDownloads' again for the transactions so that I get 'updatedDownloads' invoked.
  8. So, by calling 'startDownloads' for the transactions, 'updatedDownloads' are invoked. However, by observing the logs from appstored service, I noticed that by calling 'startDownloads' again for the transactions, it creates a second instance of the download process. And, having multiple instances of the same download process leads to download failures where the second download fails to copy the content to the destination folder because the destination folder is not empty because the first download already copied the content in the same location.