Swiftpack.co - Package - codykerns/PurchasesHelper

GitHub release (latest by date) GitHub issues GitHub license


A set of helper utilities to use for building paywalls with RevenueCat's Purchases iOS SDK.


Swift Package Manager

Add this repository as a Swift Package in Xcode.



Many developers have paid apps that they would like to convert to subscription apps. PurchasesHelper includes CompatibilityAccessManager to be used as a source of truth for entitlement access.

The easiest way to get started is to call configure on the shared instance of CompatibilityAccessManager after you initialize the Purchases SDK and provide an array of entitlement names and versions. For example, if your paid app was version 1.0 (50) and your subscription update is 1.1 (75), register your entitlement like the following:

CompatibilityAccessManager.shared.configure(entitlements: [
    .init(entitlement: "premium_access", versions: ["50"])

If you don't want purchase restoration on launch, simply register an entitlement to a set of app versions that should be granted access.

    .init(entitlement: "premium_access", versions: ["50"])

As CompatibilityAccessManager is now your source of truth for entitlement access, you have a few options for checking if entitlements are active.

If you want CompatibilityAccessManager to asynchronously fetch purchaserInfo and check if your entitlement is active between RevenueCat or your registered entitlements, call isActive on the shared CompatibilityAccessManager. This is safe to call as often as you need, as it relies on the Purchases SDK caching mechanisms for fetching purchaserInfo:

CompatibilityAccessManager.shared.isActive(entitlement: "premium_access") { (isActive, purchaserInfo) in


Or, you can check synchronously from an instance of PurchaserInfo:

purchaserInfo.isActive(entitlement: "premium_access")


In sandbox mode, the originalApplicationVersion is always '1.0'. To test different versions and how they behave, set the sandboxVersionOverride property to simulate a version number while only in sandbox mode:

CompatibilityAccessManager.shared.sandboxVersionOverride = "50"

Package Formatting

Although RevenueCat makes subscription logic simple, displaying the length and terms of a subscription package is not trivial when considering introductory offers, as well as recurring attributes that must be shown on your paywall.

Package Title

PurchasesHelper adds new properties to RevenueCat's Package objects.

var title = myPackage.displayTitle
// displayTitle = '1 Month'

title = myPackage.displayTitleRecurring
// title = 'Monthly'

Package Terms

PurchasesHelper adds a new method to RevenueCat's Package objects that builds a string to display subscription terms to a customer.

let terms = myPackage.packageTerms()
// terms = '3 day free trial, then $24.99/year'

Set recurring to false to format your terms as non-recurring, like:

let terms = myPackage.packageTerms(recurring: false)
// terms = '3 day free trial, then $24.99 for 1 year'

Package Sorting

Easily sort an array of Package objects.

After fetching offerings, sort the availablePackages property or any array of Package objects with the new sorted(by:) method.

let packages = offering.availablePackages.sorted(by: .timeAscending)
// packages = [1 month, 3 month, 6 month]

let packages = offering.availablePackages.sorted(by: .timeDescending)
// packages = [6 month, 3 month, 1 month]

The available sorting options are:

Sorts by shortest duration -> longest duration

Sorts by longest duration -> shortest duration

Sorts by packages that have an introductory price (e.g. free trial) first. Requires iOS 11.2 minimum.


Stars: 4

Used By

Total: 0


0.1.4 - 2020-08-27 14:59:01

Adds support for iOS 9.3. Changes .configure to be a method on the shared instance of CompatibilityAccessManager.

0.1.3 - 2020-08-27 14:15:31

Reverts minimum iOS version to 11.2

0.1.2 - 2020-08-20 17:05:45

Fixes closure not being called for the configure method. Adds support for iOS 9/10 for consistency with Purchases SDK.

v0.1.1 - 2020-08-18 20:42:37

Adds new configure method in CompatibilityAccessManager that automatically restores transactions if no originalApplicationVersion is available.

v0.1.0 - 2020-08-18 18:28:46