Interpret originalAppVersion as build number

This commit is contained in:
Davide De Rosa 2019-10-31 20:53:47 +01:00
parent 395ee83981
commit 5a7adf0721
1 changed files with 9 additions and 9 deletions

View File

@ -33,15 +33,13 @@ import PassepartoutCore
private let log = SwiftyBeaver.self private let log = SwiftyBeaver.self
class ProductManager: NSObject { class ProductManager: NSObject {
private static let lastFullVersionNumber = "1.8.1" private static let lastFullVersionBuild = 2016 // 1.8.1
private static let lastFullVersionBuild = "2016"
static let shared = ProductManager() static let shared = ProductManager()
private let inApp: InApp<Product> private let inApp: InApp<Product>
private var purchasedAppVersion: String? private var purchasedAppBuild: Int?
private(set) var purchasedFeatures: Set<Product> private(set) var purchasedFeatures: Set<Product>
@ -51,7 +49,7 @@ class ProductManager: NSObject {
private override init() { private override init() {
inApp = InApp() inApp = InApp()
purchasedAppVersion = nil purchasedAppBuild = nil
purchasedFeatures = [] purchasedFeatures = []
super.init() super.init()
@ -106,14 +104,16 @@ class ProductManager: NSObject {
return return
} }
purchasedAppVersion = receipt.originalAppVersion if let originalAppVersion = receipt.originalAppVersion, let buildNumber = Int(originalAppVersion) {
purchasedAppBuild = buildNumber
}
purchasedFeatures.removeAll() purchasedFeatures.removeAll()
if let version = purchasedAppVersion { if let buildNumber = purchasedAppBuild {
log.debug("Original purchased version: \(version)") log.debug("Original purchased build: \(buildNumber)")
// treat former purchases as full versions // treat former purchases as full versions
if version <= ProductManager.lastFullVersionNumber { if buildNumber <= ProductManager.lastFullVersionBuild {
purchasedFeatures.insert(.fullVersion) purchasedFeatures.insert(.fullVersion)
} }
} }