In-App Purchase Tutorial: Getting Started
- Getting Started
- Creating an App ID
- Checking Your Agreements
- Creating an App in iTunes Connect
- Creating In-App Purchase Products
- Creating a Sandbox User
- Project Configuration
- Listing In-App Purchases
- Purchased Items
- Making Purchases (Show Me The Money!)
- Making a Sandbox Purchase
- Restoring Purchases
- Payment Permissions
- Where To Go From Here?
One of the great things about building iOS apps is that you have lots of choices when it comes to monetizing your app: plain vanilla paid apps, free apps supported by ads, or even apps that support in-app purchases.
An in-app purchase (or IAP) allows developers to charge users for specific functionality or content while using an app. Implementing IAPs is particularly compelling for several reasons:
- It’s an extra way to earn money, in addition to simply selling the app for a fee upfront. Some users are willing to spend a lot more on extra content or features.
- An app can be offered for free, which makes it a no-brainer download for most people. Free apps will typically get many more downloads than paid apps. If users enjoy the app, then they can purchase more content or functionality later.
- You can display advertisements to the user in a free app with an option to remove them by purchasing an IAP.
- Following the initial release of an app, new paid content can be added to the same app instead of having to develop a brand new app to earn more money.
In this in-app purchase tutorial, you’ll leverage IAPs to unlock extra content embedded in an app. You’ll need to be familiar with basic Swift and iOS programming concepts. If these are unfamiliar topics, then check out our range of Swift tutorials before getting started. You’ll also need a paid developer account, with access to both the iOS Developer Center and App Store Connect.
In this in-app purchase tutorial, you’ll build a small app called “RazeFaces”, which allows users to buy a “RazeFace”, which is a neat illustration commonly used on this site for books and videos.
Download the materials using the link at the top and open the starter project in Xcode. Build and run to see what it does so far. The answer is: Not a lot! You’ll see an empty table view, with a single Restore button in the navigation bar, which will be hooked up later to restore purchases.
Upon finishing this tutorial, there will be a list of RazeFaces listed in the table view which you’ll be able to buy. If you delete and reinstall the app, the Restore button will reinstate any previously purchased RazeFaces.
Head over to Xcode to take a quick look at the code. The main view controller is in MasterViewController.swift. This class displays the table view which will contain a list of available IAPs. Purchases are stored as an array of
MasterViewController is using an object called
RazeFaceProducts.store of type
IAPHelper to do the heavy lifting. Take a look at their respective code files, RazeFaceProducts.swift and IAPHelper.swift.
RazeFaceProducts is a simple struct that contains some information about the products in the app, and
IAPHelper does all the important work of talking to StoreKit. The methods are all stubbed out at the moment, but you’ll fill them out in this tutorial to add IAP functionality to the app.
Before writing any code to incorporate IAP, you’ll first need to do some setup in the iOS Developer Center and App Store Connect.
Creating an App ID
First, you need to create an App ID. This will link together your app to your in-app purchaseable products. Login to the Apple Developer Center, then select Certificates, IDs & Profiles.
Next, select Identifiers > App IDs, and click + in the upper right corner to create a new App ID.
Fill out the information for the new App ID. Enter RazeFace IAP Tutorial App for the Name. Choose Explicit App ID and enter a unique Bundle ID. A common practice is to use your domain name in reverse (for example, com.razeware.razefaces). Make note of the Bundle ID as it will be needed in the steps that follow.
Scroll down to the App Services section. Notice that In-App Purchase and GameCenter are enabled by default. Click Continue and then Register and Done.
Congratulations! You have a new App ID! Next, you’ll create a matching app in App Store Connect.
Checking Your Agreements
Before you can add IAPs to an app in iTunes Connect, you must do two things:
- Make sure you have accepted the latest Apple Development Program License Agreement on developer.apple.com.
- Make sure you have accepted the latest Paid Applications agreement in the Agreements, Tax, and Billing section in App Store Connect.
If you have not done this, usually iTunes Connect will give you a warning like the following:
If you see something like the above, follow the steps to accept the appropriate agreements.
It’s also good to double check the Agreements, Tax, and Banking section in iTunes Connect:
If you see a section entitled Request Contracts containing a row for Paid Applications, then click the Request button. Fill out all the necessary information and submit it. It may take some time for your request to be approved. Sit tight!
Otherwise, if you see Paid Applications listed under Contracts In Effect, then it looks like you’ve already done this step! Nice job!
Creating an App in iTunes Connect
Now to create the app record itself, click App Store Connect in the upper left corner of the page, then click My Apps.
Next, click + in the upper left corner of the page and select New App to add a new app record. Fill out the information as shown here:
You won’t be able to use the exact same app Name that you see here, because app names need to be unique across the App Store. Perhaps add your own initials after the example title shown in the screenshot above.
Click Create and you’re done!