Guide to Auto-Renewable Subscriptions in Swift

Anurag Pandey

AccuWeather Senior iOS Developer

June 4, 2021

Image

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

Step 1: Set up a subscription product in App Store Connect

Login to the iTunes Connect in-app purchases and create a subscription product as shown below:

In-App Purchases

Configure Your Subscription Product Here

Image

In-App Purchases

Configure Your Subscription Product Here

Image

In-App Purchases

Configure Your Subscription Product Here

Image

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.

App-Specific Shared Secret

This is where you Manage App-Specific Shared Secret

Image

App-Specific Shared Secret

This is where you Manage App-Specific Shared Secret

Image

Let's Dive Into Coding

Now we have all the configuration done, we can get into some coding.

Step 3: Create StorekitHandler

First, create a StoreKitHandler class that imports StoreKit. Here is a code sample of how to initialize StorekitHandler that pulls all the products from the App Store:
Image
StoreKitHandler needs to conform to SKPaymentTransactionObserver and SKProductsRequestDelegate. With our SKProductsRequest delegate set and the request started, we need a way to grab the response and implement the SKProductsRequest delegate method:
Image

Step 4: Initiate a purchase and restore a request

Now we are all set up to handle the purchase request, let’s get into how to initiate a purchase and restore a request:
Image

Step 5: Confirm request is successful

If your product request is successful, we just need to observe the purchase response SKPaymentTransactionObserver’s paymentQueue method. paymentQueue method contains a list of transactions and each transaction has transactionState as below:
Image
Your app may need to support multiple countries and is supposed to show the price in a localized currency. Apple has made that easy for us. SKProduct contains price details and can be accessed as below:
Image
A successful purchase event in the paymentQueue method doesn’t signify a successful purchase, because a successful purchase event means that purchase was done in the past. It doesn’t mean a subscription is valid. To verify the validity of a subscription product, we need to validate receipt.

Subscription Best Practices

Here are a few important best practices to work by:

 

    1. 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.

 

  1. 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

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.

AccuWeather Enterprise Solutions, the world's leading commercial weather source partnering with more than 240 of Fortune 500 companies and thousands of businesses and government agencies worldwide, provides the most accurate, actionable weather data, forecasts, and intelligence that saves lives, protects property, drives revenue, minimizes risk, increases productivity, and more for clients worldwide. AccuWeather Enterprise Solutions has focused on the business impacts of weather for over 50 years, serving clients in all 50 states in the United States and worldwide including all of North America, Europe, Africa, Australia, South America and Asia. Clients across all industries rely on AccuWeather Enterprise Solutions for the most accurate weather information and insights to drive quantifiable business results. Government and emergency management agencies also rely on AccuWeather for the best forecasts of severe weather events - floods, tornadoes, hurricanes, cyclones and others - available from any source. By forecasting and communicating the weather the most accurately and effectively worldwide, focusing on impacts - telling people how, why, and what they need to do in order to save lives and minimize losses - AccuWeather has saved tens of thousands of lives and tens of billions of dollars in property damage.

Related Posts

Press Release

Heating bills on the rise across the eastern half of the country amid widespread bitter cold

> Heating demand is 115% to 150% of historical averages in areas of the eastern and central U.S. impacted by intense cold between Jan. 15 and Feb 8, according to a new AccuWeather analysis > Extreme cold and gusty winds will return to the Upper Midwest and the Northeast this weekend before the frigid pattern finally starts to ease next week > Check AccuWeather RealFeel® Temperature forecasts in your area > Request an interview with an AccuWeather® Expert Meteorologist > Download the latest AccuWeather® forecast graphics > Get the latest updates in the AccuWeather Newsroom AccuWeather® Global Weather Center - Feb. 5, 2026 – AccuWeather expert meteorologists say people and businesses in more than 30 states across the eastern half of the country should prepare for heating costs to be significantlyhigher than the historical average through mid-February. "Millions of people across the eastern U.S. are facing...

Fri, 06 Feb 2026 11:20:35 GMT

Press Release

Florida freeze causes citrus damage and burst pipes, contributing to costly impacts and losses from extreme cold

> 8% to 10% of Florida's citrus crop on the trees may have been damaged by recent freezing conditions  > Record-shattering cold led to pipes freezing and bursting across Florida, contributing to an AccuWeather preliminary estimate of total damage and economic loss of $13-$15 billion  > Check AccuWeather RealFeel® Temperature forecasts in your area   > Request an interview with an AccuWeather® Expert Meteorologist   > Download the latest AccuWeather® forecast graphics   > Get the latest updates in the AccuWeather Newsroom   AccuWeather® Global Weather Center - Feb. 3, 2026 – A deep freeze gripping much of the eastern half of the nation has brought disruptive and costly impacts to Florida, including frozen and burst pipes, as well as damage to some citrus crops....

Tue, 03 Feb 2026 17:49:57 GMT

Press Release

Bomb cyclone and deep freeze reaching Florida citrus groves cause an estimated $13 billion to $15 billion in total damage and economic loss

> Blizzard conditions, powerful winds and coastal flooding disrupted travel, commerce, and deliveries across the Southeast and mid-Atlantic over the weekend > Heavy snow from the bomb cyclone that blanketed ice and snow from the previous winter storm is compounding cleanup and recovery efforts in some areas > Arctic air that surged deep across Florida over the weekend is putting citrus and other crops at greater risk of freeze damage > Intense cold is pushing energy demand higher across the eastern half of the country, with elevated heating costs expected through mid-February for millions of peopl3 > Check AccuWeather RealFeel® Temperature forecasts in your area   > Request an interview with an AccuWeather® Expert Meteorologist   > Download the latest AccuWeather® forecast graphics   > Get the latest updates in the AccuWeather...

Mon, 02 Feb 2026 21:44:54 GMT