1

I'm a bit new to coding and to Revenue Cat. I just want to make sure this will work before transitioning from sandbox to production, since there's no way to test it in sandbox.

Purchases.shared.restoreTransactions { (purchaserInfo, error) in

        let originalPurchaseDate = purchaserInfo?.originalPurchaseDate

        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy/MM/dd HH:mm"
        let switchOverDate = formatter.date(from: "2020/06/29 00:00")

        if originalPurchaseDate! < switchOverDate! {
            // unlock all content
        }
}

Will this let me grandfather in my old users (who paid for my app) when I switch to subscription?

Thank you!

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
zakray
  • 135
  • 1
  • 8
  • 1
    "grandfather", I think there is something lost in translation here. – Joakim Danielson Jul 01 '20 at 13:29
  • 2
    Nothing lost here, _grandfather in old users_ means that he wants to allow old users (already paid for the app) to use the application for free when the business model will be switched to the subscription. I wouldn't say it's a well known term, but it's used pretty often. – zrzka Jul 01 '20 at 15:04
  • Thats right, thanks @zrzka – zakray Jul 02 '20 at 00:10
  • This wont work. [`restoreTransactions`](https://sdk.revenuecat.com/ios/Classes/RCPurchases.html#/c:objc(cs)RCPurchases(im)restoreTransactionsWithCompletionBlock:) restores in-app purchases. What you're looking for is the App Store receipt validation and the [original application version](https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW_9) (= `CFBundleVersion` aka build version). – zrzka Jul 02 '20 at 06:52
  • Your last paid version of the app has a build version set to 15. Your new free version (with in-app purchases) of the app has a build version set to 16. Get the App Store receipt, validate it, extract build version and grandfather the user if the build version is <= 15. Original application version corresponds to the value of `CFBundleVersion` (in iOS) in the `Info.plist` file when the purchase was originally made. Lot of tutorials [about it](https://fluffy.es/migrate-paid-app-to-iap/), [Decoding an Apple App Store Receipt](https://www.revenuecat.com/blog/dissecting-an-app-store-receipt), ... – zrzka Jul 02 '20 at 06:58
  • Thank you! Are you saying RevenueCat has no way to solve this problem using their SDK? – zakray Jul 02 '20 at 13:07
  • This will work. [ `originalPurchaseDate`] (https://sdk.revenuecat.com/ios/Classes/RCPurchaserInfo.html#/c:objc(cs)RCPurchaserInfo(py)originalPurchaseDate). Using dates is actually more capable then just checking for the app version; especially if your pricing wasn't tied to specific app versions. You could white list certain date ranges if you needed to, but the accepted answer is ideal if it meets your needs. – hidden-username Oct 30 '20 at 18:41

1 Answers1

1

You'll actually want to check the original application version here. This is available on the RevenueCat iOS SDK and will be the CFBundleVersion of the original app version the user downloaded.

Purchases.shared.restoreTransactions { (purchaserInfo, error) in
    
    // Make sure there weren't any errors...
    
    if let originalApplicationVersion = purchaserInfo?.originalApplicationVersion {
        if originalApplicationVersion < "your_build_number_string" {
            // Legacy user! Unlock content
        }
    }
    
    // Check if user restored another purchase...
}

Important:

Remember the CFBundleVersion is the build number, not the app version. Also:

In the sandbox environment, the value of this field is always “1.0”.

Source: https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html

enc_life
  • 4,973
  • 1
  • 15
  • 27
  • Just to confirm-- this doesn't require the user to have made IAPs? Because my users only paid up front. – zakray Jul 02 '20 at 16:36
  • 1
    That's correct, in production a device receipt gets created upon installation that contains the original application versionl – enc_life Jul 06 '20 at 14:01
  • @enc_life Where can you find the build number for your app ? (What I am guessing is that it's not a build number of a specific version, after all every version can have similar build numbers) – ChesterK2 Dec 02 '20 at 17:37
  • I note that restoreTransactions has been renamed by RevenueCat to restorePurchases – mackworth May 25 '22 at 21:22