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:
Create an instance of this observer class to act as the observer of changes to the payment queue:
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
SKPayment instance automatically when the content of the payment queue changes upon resuming or while running your app.
Implement the transaction observer:
It is important to add the observer at launch, in
application:, 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
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.