In-App Purchases enable users to buy in-app products from your app. This can help you retain customers and grow your revenue. In-app purchases also let you provide promotions that encourage customers to re-engage with your app.
Adding In-App Purchases in iOS
Creating in-app purchases requires creating and submitting products in App Store Connect, Apple’s developer dashboard. This process involves defining the details of each product, including its name, pricing, and description. In addition, you must upload screenshots to verify that the product is accurate.
Implementing in-app purchases is a complex process that can be overwhelming for many developers. However, the following tutorial will walk you through all the steps needed to create in-app purchase support in your app.
How to Create In-App Purchases in an iPhone or iPad App
This tutorial covers the basic steps of adding in-app purchases to an iPhone or iPad app using StoreKit 2. The goal is to create a simple, yet powerful app that offers a range of in-app products to the user.
Start by creating a project in Xcode and putting it on the development server. Make sure you have the correct credentials to connect to Apple’s servers and test your app.
Then, add the TInAppPurchase module to your project and configure it to connect to your in-app payment service. To do this, you must first call connectAsync, which initializes the module and establishes a connection with your in-app payment service. This method must be called before anything else in the app, as a failure to do so will cause an error.
To test the in-app purchase module, you can use a sandbox environment or StoreKit testing in Xcode. For this purpose, you can also use an iPhone or iPad simulator that supports the App Store APIs.
How to Restore Purchases
When your application uses in-app purchases, you can restore completed transactions. This allows you to re-use a purchase that a user previously made, and prevents the app from losing the purchase data. This functionality is required by the App Store Review Guidelines, section 3.1.1.
Restoring a purchase is a common use case for in-app purchase apps, and it’s a good idea to implement it. This will ensure that the purchase information is always up to date, preventing your app from being removed from the store for inadvertently overselling or charging more than a customer was actually entitled to.
This feature works offline, and StoreKit automatically keeps all transaction records up to date when a user is not connected to the internet. This is a great advantage for developers, but it’s important to remember that this functionality can take some time to refresh.
It can also be a pain to manage, as you must manually update each restored purchase with its corresponding information on the iOS StoreKit object. When you restore a purchase, StoreKit creates a new object with the purchaseTime and orderId. This information can be inaccurate, and it’s recommended to use the original purchase time and orderId for restoration purposes.