0

我正在为我的 iOS 应用程序购买应用程序。Apple 拒绝了我的二进制文件,因为我没有恢复购买的产品。在我的应用程序中,一旦用户点击产品图标,如果项目被锁定,他/她将定向到应用内购买过程,否则产品将打开。没有视觉购买按钮。现在苹果说要提供恢复按钮?谁能告诉我如何处理这个?我努力了

- (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 方法,以便我可以获取已购买项目的列表,然后直接通知用户他/她是否已经购买。

4

1 回答 1

3

你如何设置的代表[SKPaymentQueue defaultQueue]?我猜你已经喜欢了:

[[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

于 2013-04-14T16:02:53.267 回答