restoreCompletedTransactions

restoreCompletedTransactions

开发iPhone应用程序时,restoreCompletedTransactions遇到了一些麻烦。在沙盒环境中工作时,会出现下面列出的所有问题。该应用尚未销售。它是使用在模拟器5.0和5.1中运行的Xcode 4.3.2开发的。我遇到的问题是:


每次启动应用程序并放置对addTransactionObserver的调用时,都会通过购买交易调用updatedTransactions。在每个回调中,我的代码都调用finishTransaction:来完成购买,但是,每次我启动该应用程序时,都会一直发生此问题。确认完全相同的购买。
调用[[SKPaymentQueue defaultQueue] restoreCompletedTransactions]不会列出该帐户购买的所有非消耗性物品。我有2笔非消耗性物品的购买,每次只有1笔退货。如果我尝试购买列表中缺少的物品,我将收到一条消息,指示该物品已被购买。列表中缺少的项目不是我遇到问题1(上面列出的)的项目。


在这一点上,我完全陷入困境。我的应用程序依靠AppStore返回有关非消耗品的信息,因为我们没有将此数据保存在自己的服务器中。但是,我们需要确保AppStoreKit返回所有已购买商品的列表。不只是一些。

这是我用来测试restoreCompletedTransactions的相关代码:

- (void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    NSLog(@"updatedTransactions started. -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ");
    NSLog(@"Number of transactions received: %d.", [transactions count]);
    int count = 0;
    for (SKPaymentTransaction *trans in transactions)
{
    NSLog(@"Data for transaction %d: ", ++count);
    NSString *transId = [trans transactionIdentifier];
    switch ([trans transactionState])
    {
        case SKPaymentTransactionStatePurchasing:
            NSLog(@"Purchasing transaction: %@", transId);
            if (transId == nil)
            {
                NSLog(@"    Original transaction Id: %@", [[trans originalTransaction] transactionIdentifier]);
            }

            NSLog(@"     No action taken in update");
            break;
        case SKPaymentTransactionStateFailed:
            NSLog(@"Purchase transaction failed for transaction %@", transId);
            NSLog(@"     Error %d (%@)", [[trans error] code], [[trans error] localizedDescription]);
            NSLog(@"     Action Taken:  finish transaction.");
            [queue finishTransaction: trans];
            break;
        case SKPaymentTransactionStatePurchased:
            NSLog(@"Purchased transaction %@", transId);
            NSLog(@"     Purchased qty %d of  product %@", [[trans payment] quantity], [[trans payment] productIdentifier]);
            NSLog(@"     Action: called [queue finishTransaction:] to complete purchase");
            [queue finishTransaction: trans];
            break;
        case SKPaymentTransactionStateRestored:
        {
            SKPayment *paym = [trans payment];
            SKPaymentTransaction *origTrans = [trans originalTransaction];
            SKPayment *origPayment = [[trans originalTransaction] payment];
            NSLog(@"Transaction restored: %@ with original transaction %@", transId, [[trans originalTransaction] transactionIdentifier]);
            NSLog(@"     TRANSACTION DATA:");
            NSLog(@"           purchased %d of product %@ on %@.",
                  [paym quantity],
                  [paym productIdentifier],
                  [[trans transactionDate] description]);

            NSLog(@"     ORIGINAL TRANSACTION DATA:");
            NSLog(@"           purchased %d of product %@ on %@.",
                  [origPayment quantity],
                  [origPayment productIdentifier],
                  [[origTrans transactionDate] description]);

            NSLog(@"     No action taken.");
            break;
        }

        default:
            NSLog(@"Unexpected transaction state:  %d", [trans transactionState]);
            NSLog(@"     No action taken.");
            break;
    }
}

NSLog(@"");
NSLog(@"updatedTransactions ended. -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ");
}

- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
NSLog(@"Restore completed transactions finished.");
NSLog(@"     Number of transactions in queue:  %d", [[queue transactions] count]);
for (SKPaymentTransaction *trans in [queue transactions])
{
    NSLog(@"          transaction id %@ for product %@.", [trans transactionIdentifier], [[trans payment] productIdentifier]);
    NSLog(@"          original transaction id: %@ for product %@.", [[trans originalTransaction] transactionIdentifier],
          [[[trans originalTransaction] payment]productIdentifier]);
    }
NSLog(@"");
}

// Method to restore transactions when user clicks button in application
- (void) onRestoreCompletedTransactions:(id)sender
{
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

最佳答案

您是否在尝试每次应用程序启动时调用restoreCompletedTransactions?如果您想要所有交易的清单,则可以提出一个SKProductsRequest

 SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productsSet];
    productsRequest.delegate = self;
    [productsRequest start];


如果您想获取completedTransactions而又不找回所有东西,请显示日志。

08-05 08:21