When handling SKDownload
updates I'm not sure how to react to a .failed
state.
I've seen the guidance posted in Apple's Developer Forum, but that implies that I must wait until the user exits and relaunches the app to restart the download.
Later when the user relaunches the app and the addTransactionObserver method is called at launch time, the transaction observer will detect the incompleteTransaction and notify the app via the updatedTransactions delegate method. The app can again retry to download the hosted content.
Contradicting that, in this tutorial, I'm instructed to do the opposite, and finish the transaction to let the user attempt to download again by restoring the purchase.
There are a number of ways to improve the user experience even if the download failed... ...We could finish the transaction and the user can use the restore button to download the files.
If we give the user options then the transaction should not be finished until we are sure that we don’t use it anymore (e.g. if you plan to resume the download later then don’t finish the transaction).
This implies that I can resume a failed download. Is that possible?
My paymentQueue: updatedDownloads
method is below:
public func paymentQueue(_ queue: SKPaymentQueue, updatedDownloads downloads: [SKDownload]) {
downloads.forEach ({ (download) -> Void in
switch download.state {
case .active:
// Update the UI to allow user to pause/cancel download
case .cancelled:
// Update UI to show download cancelled
queue.finishTransaction(download.transaction)
case .failed:
let description = download.error?.localizedDescription
// <-------------------- retry the download? What should I do here?
case .finished:
// Update the UI to reflect download complete
queue.finishTransaction(download.transaction)
case .paused:
// Update the UI to allow user to resume download
case .waiting:
// Begin download immediately, on advice of: https://stackoverflow.com/a/23602553/3718806
queue.start([download])
}
})
}
I expect my users to be able to reattempt a failed download, without having to relaunch the app.
How can I achieve this?