viggio24
viggio24

Reputation: 12366

How to retrieve an SKDownload of an already purchased content

The standard in app purchase flow when there is hosted content is:

  • do the transaction
  • when the transaction enters in "purchased" state, retrieve the SKDownload and start downloading
  • when downloading is done, then we can declare the transaction as "finished"
  • This is fine. Imagine we want to restore all purchased contents, this is because we delete and re-installed our app or simply because we installed it in another device. Now, and this is confirmed by WWDC 2012 session on the subject, when you restore all purchases you will get the full list of contents to restore but probably you don't want to download all of them. In such case you should offer the user the choice of which content to download and then queue the SKDownload of the chosen product; once the the download terminates and the content is successfully installed, you can declare the transaction finished. What the session video didn't say instead is what you should do with the rejected or delayed downloads. As far as I know there is no way to save the SKDownload somewhere and retrieve it later and there is no API to ask iTunes a thing like this "give me the SKDownload of this already purchased product". So according to me there are two options to walk-around this case:

  • you will ask to restore the non-purchased stuff again; this is not elegant but it works
  • you start the procedure and then you pause it; this will be resumed later. But this solution has several drawbacks: you have no control of how the system manages the SKDownload and it could cancel if after a certain amount of time. I never tried this solution.
  • Did someone else faced this issue and found a better solution? does it make sense to open an enhancement request with Apple?

    Upvotes: 3

    Views: 968

    Answers (1)

    odyth
    odyth

    Reputation: 4336

    I always do it is as you suggested, and just "rebuy" the purchased items so it goes through the normal purchase flow. You can't mark the transaction as finished until your done with the download. So if you pause it and the app dies when your app is launched again the queue will go off and try to finish the purchase which would start your download logic again. That seems more annoying as a user constantly having this thing popup when I open the app to finish the purchase.

    The SKDownload docs say;

    Your app never directly creates a SKDownload object. Instead, after a payment is processed, your app reads the transaction object’s downloads property to retrieve an array of SKDownload objects associated with the transaction.

    Upvotes: 1

    Related Questions