Mac Developer Library

Developer

StoreKit Framework Reference SKPaymentTransactionObserver Protocol Reference

Options
Deployment Target:

On This Page
Language:

SKPaymentTransactionObserver

The SKPaymentTransactionObserver protocol declares methods that are implemented by observers of an SKPaymentQueue object.

An observer is called when transactions are updated by the queue or removed from the queue. An observer should process all successful transactions, unlock the functionality purchased by the user, and then finish the transaction by calling the payment queue’s finishTransaction: method.

Inheritance


Not Applicable

Import Statement


Swift

import StoreKit

Objective-C

@import StoreKit;

Availability


Available in OS X v10.7 and later.
  • Tells an observer that one or more transactions have been updated. (required)

    Declaration

    Swift

    func paymentQueue(_ queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!)

    Objective-C

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

    Parameters

    queue

    The payment queue that updated the transactions.

    transactions

    An array of the transactions that were updated.

    Discussion

    The application should process each transaction by examining the transaction’s transactionState property. If transactionState is SKPaymentTransactionStatePurchased, payment was successfully received for the desired functionality. The application should make the functionality available to the user. If transactionState is SKPaymentTransactionStateFailed, the application can read the transaction’s error property to return a meaningful error to the user.

    Once a transaction is processed, it should be removed from the payment queue by calling the payment queue’s finishTransaction: method, passing the transaction as a parameter.

    Import Statement

    Objective-C

    @import StoreKit;

    Swift

    import StoreKit

    Availability

    Available in OS X v10.7 and later.

  • Tells an observer that one or more transactions have been removed from the queue.

    Declaration

    Swift

    optional func paymentQueue(_ queue: SKPaymentQueue!, removedTransactions transactions: [AnyObject]!)

    Objective-C

    - (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray *)transactions

    Parameters

    queue

    The payment queue that updated the transactions.

    transactions

    An array of the transactions that were removed.

    Discussion

    Your application does not typically need to implement this method but might implement it to update its own user interface to reflect that a transaction has been completed.

    Import Statement

    Objective-C

    @import StoreKit;

    Swift

    import StoreKit

    Availability

    Available in OS X v10.7 and later.

  • Tells the observer that the payment queue has updated one or more download objects. (required)

    Declaration

    Swift

    optional func paymentQueue(_ queue: SKPaymentQueue!, updatedDownloads downloads: [AnyObject]!)

    Objective-C

    - (void)paymentQueue:(SKPaymentQueue *)queue updatedDownloads:(NSArray *)downloads

    Parameters

    queue

    The payment queue that updated the downloads.

    downloads

    The download objects that were updated.

    Discussion

    When a download object is updated, its downloadState property describes how it changed.

    Import Statement

    Objective-C

    @import StoreKit;

    Swift

    import StoreKit

    Availability

    Available in OS X v10.8 and later.