开发者

restoreCompletedTransactions for Auto-Renewable subscriptions

开发者 https://www.devze.com 2023-03-20 21:02 出处:网络
I\'m trying to implement Auto-Renewable subscriptions in my app and having a problem: it looks like restoreCompletedTransactionsrestores transactions only from the last call of restoreCompletedTransac

I'm trying to implement Auto-Renewable subscriptions in my app and having a problem: it looks like restoreCompletedTransactions restores transactions only from the last call of restoreCompletedTransactions to now.

Fo开发者_如何学JAVAr example, if the subscription started on June 1 and I call restoreCompletedTransactions on June 15, it returns all transactions from June 1 to June, 15. Next time I call restoreCompletedTransactions on June 16 and it returns transactions from June 15 to June 16. If there are no autorenew transactions since last call of restoreCompletedTransactions it returns nothing.

Is this correct? How can I retrieve information about previous transactions?


This is counter to what I've experienced. In my experience, when you call restoreCompletedTransactions it sends you a boat-load of receipts that seems to increase each time you make that call.

But to answer your question, what Apple recommends is that you store and verify all receipts from your own server. So any time the app receives a receipt, you're supposed to send it to your server for verification and possible storage. That way it wouldn't matter if restoreCompletedTransactions is really only giving you new transactions.

In addition, when you verify an auto-renewable receipt with Apple, they'll send you the latest receipt that pertains to that subscription.


Not sure if this is a good solution, but it is an extension of the above. Do a restoreCompletedTransactions, and check the date on purchase transactions. Maybe on restored transactions (maybe someone can let us know>

// in your main code somewhere

#import <StoreKit/StoreKit.h>
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

// then, update the StoreKit callback function. kProductId is the productId for the subscription in the app store

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchasing:
                NSLog(@"Purchasing");
                break;

            case SKPaymentTransactionStatePurchased:
                if ([transaction.payment.productIdentifier
                     isEqualToString:kProductID]) {
                    NSLog(@"Purchased ");
                    // update based on transaction.transactionDate
                }
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;

            case SKPaymentTransactionStateRestored:
                NSLog(@"Restored ");
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                if ([transaction.payment.productIdentifier
                     isEqualToString:kProductID]) {
                    // update based on transaction.transactionDate
                }
                break;

            case SKPaymentTransactionStateFailed:
//                NSLog(@"Purchase failed ");
            default:
                break;
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号