Add lite version as promoted IAP
@@ -337,8 +337,38 @@ import TrueTime
switch Product(rawValue: product.productIdentifier) {
case .freeTrial:
return true
- case .liteVersion, .upgrade:
+ case .upgrade:
return false // Not purchasable from the App Store
+ case .liteVersion:
+ // Only purchasable if the full version isn't purchased
+
+ SwiftyStoreKit.restorePurchases { (results) in
+
+ var product = Product.liteVersion
+
+ for purchase in results.restoredPurchases {
+ if purchase.productId == Product.fullVersion.rawValue {
+ product = .fullVersion
+ break
+ } else if purchase.productId == Product.upgrade.rawValue {
+ product = .upgrade
+ break
+ }
+ }
+
+ if #available(iOS 13.0, *) {
+ let keyWindow = UIApplication.shared.connectedScenes
+ .filter({$0.activationState == .foregroundActive})
+ .map({$0 as? UIWindowScene})
+ .compactMap({$0})
+ .first?.windows
+ .filter({$0.isKeyWindow}).first
+
+ purchase(id: product, window: keyWindow)
+ }
+ }
+
+ return false
case .fullVersion:
// Give a discount if the lite version was purchased
