简体   繁体   中英

iPhone App : In App Purchase

In iPhone App for in App Purchase: when is SKPaymentTransactionStateRestored: called?

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
      switch (transaction.transactionState) {
      case SKPaymentTransactionStateRestored:
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
        break;
      }
    }
}

And how to get confirmation from apple that the app is purchased successfully means I want to Print that information in NSlog.

what should I write for that?

就我而言,仅当Apple将updateTransactions状态响应为SKPaymentTransactionStateRestoredSKPaymentTransactionStatePurchasedtransactions才能成功购买。

When the method:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray     *)transactions{

     for (SKPaymentTransaction * transaction in transactions) {        

        //process the transaction
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
                break;
           default:
                break;
    }

        }

}

is called it means that you have finished your transaction with apple and you handle three cases:

SKPaymentTransactionStatePurchased: it means that your product was bought.

SKPaymentTransactionStateFailed: your product couldn't be bought.

SKPaymentTransactionStatePurchased: This is your question. As long as your SKPaymentTransactionObserver is alive the transaction is persistant, meaning that if your client intended to buy you product but something wrong happened while delivering the product (server error or something else), when the app starts again the transaction will return to this method to finish the purchase.

I hope the info helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM