Setting Up the Transaction Observer for the Payment Queue

Enable your app to receive and handle transactions by adding an observer.


To process transactions in your app, you must create and add an observer to the payment queue. The observer object responds to new transactions and synchronizes the queue of pending transactions with the App Store, and the payment queue prompts the user to authorize payment. Your app should add the transaction observer at app launch to ensure that your app will receive payment queue notifications as soon as possible.

Create an Observer

Create and build out a custom observer class to handle changes to the payment queue:

class StoreObserver: NSObject, SKPaymentTransactionObserver {
    //Initialize the store observer.
    override init() {
        //Other initialization here.

    //Observe transaction updates.
    func paymentQueue(_ queue: SKPaymentQueue,updatedTransactions transactions: [SKPaymentTransaction]) {
        //Handle transaction states here.

Create an instance of this observer class to act as the observer of changes to the payment queue:

let iapObserver = StoreObserver()

Once you've created the transaction observer, you can add it to the payment queue.

Add an Observer

StoreKit attaches your observer to the queue when your app calls:


StoreKit can notify your SKPaymentTransactionObserver instance automatically when the content of the payment queue changes upon resuming or while running your app.

Implement the transaction observer:

import UIKit
import StoreKit

class AppDelegate: UIResponder, UIApplicationDelegate {
    // Attach an observer to the payment queue.
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        return true

    // Called when the application is about to terminate.
    func applicationWillTerminate(_ application: UIApplication) {
        // Remove the observer.

It is important to add the observer at launch, in application:didFinishLaunchingWithOptions:, to ensure that it persists during all launches of your app, receives all payment queue notifications, and continues transactions that may be processed outside the app, such as:

  • Promoted in-app purchases

  • Background subscription renewals

  • Interrupted purchases

The observer must be persistent so it is not deallocated when the app is sent to the background. Only a persistent observer can receive transactions that may occur while your app is in the background, such as a renewal transaction for an auto-renewable subscription.

See Also


Offering, Completing, and Restoring In-App Purchases

Fetch, complete, and restore transactions in your app.


A queue of payment transactions to be processed by the App Store.


A set of methods that process transactions, unlock purchased functionality, and continue promoted in-app purchases.


The protocol implemented to provide information needed to complete transactions.


An abstract class that represents a request to the App Store.