6

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

  1. 每次应用程序启动并调用 addTransactionObserver 时,都会调用 updatedTransactions 并购买一笔交易。在每次回调时,我的代码都会调用 finishTransaction: 来完成购买,但每次我启动应用程序时都会出现这个问题。对完全相同的购买进行确认。
  2. 调用 [[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];
}
4

2 回答 2

0

一个 SKProductsRequest 将使您返回一个 SKProduct 实例列表。SKProduct 类在我的阅读中没有购买信息。我认为您确实确实想使用 restoreCompletedTransactions 并取回 SKPaymentTransaction 实例的列表。也就是说,我在使用沙盒帐户时遇到了同样的问题。我得到了一份不完整的交易清单(48 个中的 23 个)。但是,如果我确实选择购买已购买但未恢复的非消耗品,则商店将其视为已购买的物品并将退回该物品的恢复。

有运气解决这个问题吗?

于 2014-02-07T19:20:20.423 回答
0

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

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

如果您想获得已完成的交易并且没有取回所有内容,请显示日志。

于 2012-07-23T17:30:11.693 回答