How to change from paid version to free version with subscriptions in iOS / StoreKit 2

393 Views Asked by At

I have an existing app on the app store since many years. Users had to pay to download the app. Now I want to shift to a freemium model by implementing in-app purchases. And I want to be fair to previous-purchasers of my app.

I searched and read a lot about this topic and it is still intimidating to me, mostly because it always comes down to parse the original transaction receipt and "parse out" encrypted stuff like "Original App Version Field" ... I was so hoping, the new StoreKit 2 offers more options for this very common problem, but couldn't find it.

So here I am asking: Is there a more easy way within StoreKit 2 to retrieve more 'readable' data from the original purchase?

Any hint would be appreciated.

2

There are 2 best solutions below

1
Jorge On BEST ANSWER

According to Apple:

Use the Original API to Support Certain Features

You may need to use the original in-app purchase API if your app depends on any of the following features:

  • To provide support for the Volume Purchase Program (VPP). For more information, see Device Management.

  • To provide app pre-orders.

  • Your app changed from a premium to a freemium model, or vice versa. Use the original API for existing and legacy apps.

https://developer.apple.com/documentation/storekit/choosing_a_storekit_api_for_in-app_purchase

So, apparently, there is no way to retrieve that information with StoreKit 2, at least as of now, with iOS 15.

1
Daniel On

With iOS 16 and macOS 13.0 you can do this directly with StoreKit:

import StoreKit

do {
     // Get the appTransaction.
      let shared = try await AppTransaction.shared
        if case .verified(let appTransaction) = shared {
            // Hard-code the major version number in which the app's business model changed.
            #if os(macOS)
            let newBusinessModelVersion = "2" // CFBundleShortVersionString
            #else
            let newBusinessModelVersion = "42" // CFBundleVersion
            #endif
            
            // Get the major version number of the version the customer originally purchased.
            #if os(macOS)
            let versionComponents = appTransaction.originalAppVersion.split(separator: ".")
            let originalVersion = versionComponents[0]
            #else
            let originalVersion = appTransaction.originalAppVersion
            #endif

            NSLog("original purchased version: \(originalVersion)")

            if originalVersion < newBusinessModelVersion {
                // This customer purchased the app before the business model changed.
                // Deliver content that they're entitled to based on their app purchase.
            }
            else {
                // This customer purchased the app after the business model changed.
            }
        }
    }
catch {
    // Handle errors.
}

https://developer.apple.com/documentation/storekit/apptransaction/3954447-originalappversion