In-app purchases (IAP) is a great way to monetize your iOS and macOS applications. In the AppStore, there are applications with the “Offers In-App Purchases” label near the Buy or Get button. It means that these apps contain in-app purchases. IAP is most often used to unlock additional content or functionality. Usually, apps with in-app purchases are free. It helps engage new users and sell more features to more people.
Apple keeps 30% of the purchase price by default.
In this article, we will take a look at everything about in-app purchases — iTunes Connect settings, Swift code using and testing.
There are different types of IAP you can add:
Note: In-App Purchases can be offered only for digital items, and not for physical goods or services. For more information about it, check out Apple’s full documentation on Creating In-App Purchase Products.
Examples of IAP:
First, you need to enter your bank information. That can be done by going to the Agreements, Tax, and Banking section in iTunes Connect. When you’re done, you should have something like the following:
Next, we need to add users to the Sandbox account: project managers, testers and app owners.
Click App Store Connect in the top left corner of the window to get back to the main menu. Select Users and Roles, then click the Sandbox Testers tab. Click + next to the “Tester” title.
Fill out the information and click Save when you’re done. You can make up a first and last name for your test user, but you must use a real email address as Apple will send a verification email to the address. Once you receive that email, be sure to click the link in it to verify your address.
The email address you enter shouldn’t already be associated with an Apple ID account.
Go to the My Apps section and create an app or use an existing app if you already have one.
Click on your iTunes app and navigate to the Features section. To create a new IAP product, click on the + button and pick one of the types. Then enter the required metadata. It should look like in the pictures below.
Save the code in a separate class. I have named mine IAPHandler, but feel free to change the name. In this class, you will store everything related to In-App Purchases.
First, create variables from your IAP product ID. In my case, CONSUMABLE_PURCHASE_PRODUCT_ID and NON_CONSUMABLE_PURCHASE_PRODUCT_ID. Also, create variables for handling the IAP request and an array that will store all the available IAP products.
Additionally, I have added the callback handler. Create a closure purchaseStatusBlock(), which returns various IAP transaction statuses for clearer code. To make it even better, I have created an enumerated type called IAPHandlerAlertType, which will return a message for the suitable case.
Go to your UIViewController and then in your in viewDidLoad() function, fetch the products and also add the closure where you will get the response of the transaction that the user has made.
Then create an action where you will initialize the transaction window.
Sign in with your Sandbox User on your iOS device, navigate to your app and click the action to initiate the transaction. Don’t worry about the price on the transaction window. Since you are using a Sandbox User, nothing will be charged from your account.
By following the proper strategy, you can boost your sales up to the maximum point, and at the same time keep your users happy as they buy only what they want. Balance the pros and cons, and go for the In-App Purchases.