自2天以来,我一直在努力解决这个问题。我已经使用可下载的内容成功实现了应用内购买。但是每当我删除应用程序并恢复购买时,恢复实际上并没有下载内容。但是,如果我在 restoreTransaction 中添加下载代码,每次我删除应用程序并重新安装它时,它都不会调用导致应用程序行为异常的完成事务(这是合理的)。任何帮助表示赞赏!如果有人需要进一步解释,请告诉我。谢谢!!
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction * transaction in transactions) {
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
if(transaction.downloads)
[self download:transaction];
else
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
if(transaction.downloads)
[self restoreDownload:transaction];
else
[self restoreTransaction:transaction];
default:
break;
}
};
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedDownloads:(NSArray *)downloads
{
for (SKDownload *download in downloads)
{
switch (download.downloadState) {
case SKDownloadStateActive:
NSLog(@"Download progress = %f",
download.progress);
NSLog(@"Download time = %f",
download.timeRemaining);
break;
case SKDownloadStateFinished:
{
NSLog(@"URL %@",download.contentURL);
}
break;
default:
break;
}
}
}
- (void)completeTransaction:(SKPaymentTransaction *)transaction {
NSLog(@"completeTransaction...");
[self provideContentForProductIdentifier:transaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
- (void)restoreTransaction:(SKPaymentTransaction *)transaction {
NSLog(@"restoreTransaction...");
[self provideContentForProductIdentifier:transaction.originalTransaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
- (void)restoreDownload:(SKPaymentTransaction *)transaction {
NSLog(@"restoreDownload...");
//[self validateReceiptForTransaction:transaction];
[self provideContentForProductIdentifier:transaction.originalTransaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] startDownloads:transaction.downloads];
}
- (void)download:(SKPaymentTransaction *)transaction {
NSLog(@"Download Content...");
[self provideContentForProductIdentifier:transaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] startDownloads:transaction.downloads];
//[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}