Subscriptions are one of the ways to monetize an app. Developers can get a recurrent income and provide users with up to date content. Unlike regular purchases, where Apple takes a 30% commission, this commission reduces to 15% in case the user is subscribed during one year or longer. Important: if the user cancels the subscription, this counter resets in 60 days.
With this article, we start our series of tutorials on integrating in-app purchases into an app. Here is what we’ll be talking about:
- iOS in-app purchases, part 1: configuration and adding to the project.
- iOS in-app purchases, part 2: initialization and purchases processing.
- iOS in-app purchases, part 3: testing purchases in XCode.
- iOS in-app purchases, part 4: server-side receipt validation.
- iOS in-app purchases, part 5: the list of SKError codes and how to handle them.
In this part we will learn how to:
- Create purchases in App Store Connect.
- Configure subscriptions: set a duration, price, trial periods.
- Get a list of purchases in-app.
Before implementing your in-app purchases you have to:
- Pay for the Apple Developer account as a natural person or an entity.
- Accept all the agreements in App Store Connect. Updated agreements will appear in your App Store Connect account, it’s easy to notice them.
Let’s assume that our app will have two types of subscriptions: monthly and annual. Each of them will have a 7-day free trial.
On the application page in App Store Connect, open In-App Purchases tab → Manage. Here you can see the list of created purchases. Click (+) next to the title to create a new purchase.
You’ll see an in-app purchase dialog appear. Select Auto-Renewable Subscription.
On the next step, you will be offered to create a Subscription Group.
A Subscription Group is a set of subscriptions with the essential feature: the user cannot activate two subscriptions at the same time from the same group. Besides, all the introductory offers, such as trial subscriptions, are applied directly to the entire group. Groups serve to separate business logic in the application.
Let’s name the group Premium Access. While adding another subscription, the interface will offer you to add it to the existing group. Later you will be able to manage the groups in the In-App Purchases menu → Subscription Groups.
Next, fill out the details:
- Reference Name is the title of your subscription in App Store Connect, as well as in Sales section and the reports
- Product ID is a unique product identifier, which is used in the application code
I would recommend choosing a simple Product ID name, which could give you as much information as possible. It’s better to indicate subscription duration to ease further analytics evaluation.
Add the second product following the previous instruction.
In the end, the interface of In-App Purchases tab → Manage will look like this:
We added the purchases, but they are not ready yet to be used: status bar indicates Missing Metadata. It means we still haven’t added the information about pricing and subscription duration. We’ll fix it now.
Duration and pricing
Click on the product to configure it.
Here we need to choose a Subscription Duration. In our case, we choose 1 Month or 1 Year. Then go to the Subscription Prices menu.
You can flexibly set prices depending on the country, but we will limit ourselves to automatic prices, in USD. App Store Connect will automatically convert prices into another currency, it’s not clear how it works though. Probably you would want to change the price manually adjusting to your target market.
One of the most popular ways to increase subscriptions is a free trial:
A user activates it and uses an application for free. If he doesn’t cancel the subscription, after the trial expires, the user is being charged automatically.
The developers love free trials because they work well. Let’s learn how to enable it.
Click (+) next to the title and choose Create Introductory Offer from the list:
Choose a list of countries.
Choose the offer duration. You can set No End Date if you don’t want to limit yourself.
On the last step, you need to select an Offer Type.
As you can see in the next screenshot, there are three types:
Pay as you go — a reduced-price use: the user pays a reduced price during the initial period and then becomes a regular subscriber with standard prices.
Pay up front — a prepay use: the user pays a fixed amount of money at once and gets an opportunity to use the app during the determined period, and then also becomes a regular subscriber.
Free — a free trial, after its expiry theuser may become a subscriber.
We choose the third one and set the duration for one week.
Getting the list of SKProduct
Let’s check if the mobile app sees the purchases and then lay the groundwork for further realization of purchases.
It’s a good rule to create a class singleton for working with StoreKit. Such a class has only one instance in the entire app. A lot of productIdentifiers will store our purchases identifiers:
Only identifiers are not enough.
To fully use the purchases you need to get: price, currency, localization, discounts.
SKProduct class returns all this information and even more. To get this information, we need to request Apple. Create an object SKProductsRequest, assign “delegate” (there you will receive the result). Call the method start(), which initialize an asynchronous procedure:
If the operation is successful, productsRequest(didReceive response:) method will be called, which will contain all the relevant information:
If everything is successful, there will be two lines in the log:
However, if there is an error, then SKProduct with such an ID will not be returned. It may happen if the product has become invalid due to any reason.
The next article will be focused on how to make in-app purchases: open/close transactions, handle errors, validate receipt, and more.