Logo for tanaschita.com

How to implemet a free trial period for StoreKit 2 subscriptions in iOS

Learn how to implement StoreKit 2 introductory offers.

13 Nov 2023 · 2 min read

When setting up auto-renewable subscriptions for an iOS application with StoreKit 2, we might want to offer users a free trial period.

Let's look at how to do that.

Sponsorship logo
Preparing for a technical iOS job interview - updated for iOS 17
Check out my book on preparing for a technical iOS job interview with over 200 questions & answers. Test your knowledge on iOS topics such as Swift, SwiftUI, Combine, HTTP Networking, Authentication, SwiftData & Core Data, Concurrency with async/await, Security, Automated Testing, Machine Learning and more.
LEARN MORE

Setting up a subscription with a free trial

When setting up a StoreKit subscription in App Store Connect or via a StoreKit test file, we have the possibility to setup an introductory offer.

Introductary offers
Introductary offers.

As shown above, we can choose between 3 options:

  • Pay as you go - new subscribers pay an introductory price each billing period for a specific duration, for example 0.99 € per month for 3 months. After 3 months, subscribers pay the regular monthly price.
  • Pay up front - new subscribers pay a one-time introductory price for a specific duration, for example 0.99 € for 1 month. After 1 month, subscribers pay the regular monthly price.
  • Free trial - new subscribers access content for free for a specified duration. After the free trial period is over, they pay the regular price.

In our case, we choose the free trial option and select the duration of the free trial period.

Showing the free trial options in the iOS app

After setting up the free trial, the next step is to show it to eligible users. A user is not eligible if they already used an introductary offer of that subscription or a subscription of the same group before.

We can use the subscription's introductoryOffer property that will automatically be applied if the user is eligible. Alternatively, we can use the isEligibleForIntroOffer property on the subscription to check if the user is eligible:

func isEligibleForFreeTrial() async -> Bool {
guard let subscription = product?.subscription else { return false }
return await subscription.isEligibleForIntroOffer
}

The subscription's introductoryOffer offers different properties which represent the information we configured, for example:

If we decide to offer another option such as payAsYouGo or payUpFront, we can also use properties like displayPrice or periodCount to show relevant information to the user.

Sponsorship logo
Preparing for a technical iOS job interview - updated for iOS 17
Check out my book on preparing for a technical iOS job interview with over 200 questions & answers. Test your knowledge on iOS topics such as Swift, SwiftUI, Combine, HTTP Networking, Authentication, SwiftData & Core Data, Concurrency with async/await, Security, Automated Testing, Machine Learning and more.
LEARN MORE

Newsletter

Image of a reading marmot
Subscribe

Like to support my work?

Say hi

Related tags

Articles with related topics

storekit

swift

ios

Get started with auto‑renewable subscriptions for iOS

Learn how to implement in-app purchase subscriptions with StoreKit and SwiftUI.

11 Dec 2023 · 5 min read

Latest articles and tips

© 2024 tanaschita.com

Privacy policy

Impressum