如果Apple托管的应用内购买内容下载失败怎么办?

时间:2013-05-28 09:07:35

标签: iphone ios ipad in-app-purchase storekit

有时下载失败,我的应用程序在失败时完成交易,无处不在。但如果我完成交易,则Store Kit无法恢复失败的下载。并且似乎Store Kit在下载失败后不会自动重试下载内容,并且似乎也无法触发下载。

有人在这种情况下想出了该做什么吗?反对所有建议,直到内容完全下载并安装完成后才完成交易?

或者我必须以编程方式还原事务并忽略所有其他产品标识符吗?

1 个答案:

答案 0 :(得分:1)

您可以在应用中添加恢复购买按钮: -

//inside of an IBaction
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];


// Then this is called
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
NSLog(@"%@",queue );
NSLog(@"Restored Transactions are once again in Queue for purchasing %@",[queue transactions]);  

NSMutableArray *purchasedItemIDs = [[NSMutableArray alloc] init];
NSLog(@"received restored transactions: %i", queue.transactions.count);

for (SKPaymentTransaction *transaction in queue.transactions) {
    NSString *productID = transaction.payment.productIdentifier;
    [purchasedItemIDs addObject:productID];
    NSLog (@"product id is %@" , productID);
    // here put an if/then statement to write files based on previously purchased items
    // example if ([productID isEqualToString: @"youruniqueproductidentifier]){write files} else { nslog sorry}
  }  
 }

 [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

希望这能帮助你...... !!