SKDownloadStateFailed除了show alert之外怎么办?

时间:2013-04-24 21:50:35

标签: ios objective-c in-app-purchase storekit

我找不到正确处理StoreKit的示例或基于SKDownloadStateFailed的开源项目。他们充其量只显示UIAlertView。我无法以编程方式重试下载吗?用户如何重新下载Apple托管的内容?

我找到的唯一方法是重新开始购买。但这首先要问用户是否要花钱。在此之后,它告诉用户他已经购买了它并且可以免费下载。

1 个答案:

答案 0 :(得分:0)

您可以先暂停所有下载,然后恢复所有下载,重新启动下载。以下是我使用的辅助方法。请注意,我使用的实例变量包含对正在下载的每个SKTransaction的强引用。

- (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
}