我正在为我的iOS应用程序购买应用程序。由于没有恢复购买的产品,Apple拒绝了我的二进制文件。在我的应用程序中,一旦用户点击产品图标,如果项目被锁定,他/她将指向inApp购买流程,否则产品将开启。没有可视购买按钮。现在苹果说要提供恢复按钮?谁能告诉我如何处理这个问题?我试过了
- (void) checkPurchasedItems
{
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}// Call This Function
//Then this delegate Function Will be fired
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
alreadyPurchasedItems = [[NSMutableArray alloc] init];
NSLog(@"received restored transactions: %i", queue.transactions.count);
for (SKPaymentTransaction *transaction in queue.transactions)
{
NSString *ID = transaction.payment.productIdentifier;
[alreadyPurchasedItems addObject:ID];
}
}
在应用程序启动时,从不调用paymentQueueRestoreCompletedTransactionsFinished方法,以便我可以获取已购买项目的列表,然后直接通知用户他/她是否已购买此项目。
答案 0 :(得分:3)
如何设置[SKPaymentQueue defaultQueue]
的代理?我猜你已经像smt一样:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
之后[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
会导致以下方法被触发。因此,SKPaymentTransactionStateRestored就是您实现它的地方:
-(void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction * transaction in transactions) {
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
...
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
...
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
...
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
default:
break;
}
};
}
您可以查看本教程,最后将详细介绍恢复。 http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial