The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

Follow publication

SwiftUI, In-App Purchases and RevenueCat

Thomas Ricouard
The Startup
Published in
3 min readMay 29, 2020

--

How to implement in app purchases & subscription in a SwiftUI application

In my latest open source SwiftUI project, AC Helper (an Animal Crossing companion application) that I released on the App Store, I’ve decided to add a monthly and yearly subscription alongside a one time lifetime in app purchase.

You can find the source of the project here:

And download the application on the App Store here:

Initially I wanted to implement the in app purchase myself using StoreKit, and I actually had it working, but for subscriptions I had to handle so many edge cases, check the receipt etc…(which should all be built in feature of StoreKit). And I’ve also I’ve heard so many good words about RevenueCat that I had to try it. So I deleted my implementation and implemented their SDK.

They have a very straightforward framework and you can add it using the Swift Package Manager. A good news because in AC Helper I don’t want to use any third party dependency manager. Once added you just have to import Purchases and you can start implementing it right away. You’ll still have to reference your in app purchases on the admin area on their website, but it’s simple and well documented enough that I won’t detail it here.

In order to make it work I’ve decided to make an ObservableObject called SubscriptionManager. I’ll later inject this object as an EnvironmentObject to be able to retrieve and observe it from any views. Here is the code:

--

--

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

Thomas Ricouard
Thomas Ricouard

Written by Thomas Ricouard

📱 🚀 🇫🇷 [Entrepreneur, iOS/Mac & Web dev] | Now @Medium, @Glose 📖| Past @google 🔍 | Co-founded few companies before, a movies 🎥 app and smart browser one.

Responses (1)

Write a response