1

我已经实现了 Apple 文档中关于 IAP 中描述的应用内付款,但是当我在沙盒模式下尝试它们时,“transactionState”永远不会更改为 SKPaymentTransactionStatePurchased。(它永远保留在 SKPaymentTransactionStatePurchasing 上。)

有人知道出了什么问题吗?

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
        NSLog(@"%ld", transaction.transactionState);
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
            default:
                break;
        }
    }
}

- (void)completeTransaction:(SKPaymentTransaction *)transaction
{
    [self recordTransaction:transaction];
    [self provideContent:transaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

- (void)failedTransaction:(SKPaymentTransaction *)transaction
{
    if (transaction.error.code != SKErrorPaymentCancelled) {
        [NSAlert alertWithError:transaction.error];
    }
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

- (void)restoreTransaction:(SKPaymentTransaction *)transaction
{
    [self recordTransaction:transaction];
    [self provideContent:transaction.originalTransaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

- (void)recordTransaction:(SKPaymentTransaction *)transaction
{
    NSLog(@"Record Transaction...");
    // ToDo: Implement 'recordTransaction'.
}

- (void)provideContent:(NSString *)productIdentifier
{
    NSLog(@"Provide Content");
    // ToDo: Implement 'provideContent'.
}
4

1 回答 1

0

在不同的机器上测试相同的代码。它适用于我的开发机器上的每一个期望。似乎不是我的代码。

于 2012-04-27T09:17:44.000 回答