4

I find no examples or StoreKit-based open source projects that correctly deal with SKDownloadStateFailed. At best they show a UIAlertView. Is there nothing I can do to retry the download programmatically? And how are users supposed to re-download Apple-hosted content?

The only way I found was to re-initiate the purchase. But this asks the user first if he wants to spend money. After this it tells the user he already purchased it and can download for free.

Barney
  • 16,181
  • 5
  • 62
  • 76
openfrog
  • 40,201
  • 65
  • 225
  • 373
  • Bump. I'm trying this with the Simulator now and that might be the culprit, but after SKDownloadStateFailed:ing, there seems to be no way of reinitiating the download, not even with another purchase. – Jonny Jul 24 '13 at 09:17

1 Answers1

0

You can reinitiate the download by first pausing all downloads, and then resuming all downloads. Following are the helper methods I use. Note that I make use of an instance variable containing strong references to each SKTransaction being downloaded.

- (void)pauseAllDownloads {
    METHOD;
    for (SKPaymentTransaction *transaction in self.transactionsBeingDownloaded) {
        [[SKPaymentQueue defaultQueue] pauseDownloads:transaction.downloads];
    }
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];  //stop the dl activity icon in the status bar
}

- (void)resumeAllDownloads {
    METHOD;
    if (self.transactionsBeingDownloaded.count == 0) {
        [self restoreCompletedTransactions];
    } else {
        for (SKPaymentTransaction *transaction in self.transactionsBeingDownloaded) {
            NSLog(@"state: %i", transaction.transactionState);
            [[SKPaymentQueue defaultQueue] resumeDownloads:transaction.downloads];
        }
    }
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];  //show the dl activity icon in the status bar
}
ObjectiveTC
  • 2,477
  • 30
  • 22