Auto-renewable subscription is an iOS purchase category that allows developers to monetize their apps by charging for the content or features. To offer subscriptions, you’ll need to implement StoreKit APIs in your app, configure your subscriptions in App Store Connect and assign them to a subscription group (a group of subscriptions with different access levels, prices, and durations).
So let's dive into implementing auto-renewable subscriptions and make some money.
Configure the Subscription Product
Login to the iTunes Connect in-app purchases and create a subscription product as shown below:
Step 2: Generate app-specific shared secret key
Now that you have set up the subscription product on iTunes Connect, you need a way to fetch subscription details on the app. Apple does not provide anything built into iOS or a REST API that gives you simple subscription details. Apple does have an API (receipt validation API) that when given a user's local receipt and a shared secret generated in iTunes Connect, it returns a JSON object of the user's purchase history for your app, including their current subscription information.
In order to access the receipt validation API, you need an app-specific shared secret key. Generate the shared secret key and never regenerate it if you have a live app and use it on the App Store.
Let's Dive Into Coding
Now we have all the configuration done, we can get into some coding.
Step 3: Create StorekitHandler
Step 4: Initiate a purchase and restore a request
Step 5: Confirm request is successful
Subscription Best Practices
Here are a few important best practices to work by:
- Never store subscription data such as prices and descriptions for example, in your app. Always rely on Apple for this latest data. This will give you the ability to change prices and make unique promotional offerings without releasing a new app version.
- Describe your subscription clearly so your users know exactly what they’re buying. Also a clear description is required from Apple to avoid any App Store rejections.
Anurag Pandey
AccuWeather Senior iOS Developer
An iOS enthusiast with a passion to dive deeply into architectures, design patterns, standard principles and explore new technologies.