From 63bd33aa4ece7095bc3304e77e0ef030d24635e2 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 9 Nov 2019 17:32:00 +0100 Subject: [PATCH] Iterate feature-based products --- Passepartout-iOS/Global/Product.swift | 12 ++++++++++++ Passepartout-iOS/Global/ProductManager.swift | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Passepartout-iOS/Global/Product.swift b/Passepartout-iOS/Global/Product.swift index f3ff41cb..ebd7beff 100644 --- a/Passepartout-iOS/Global/Product.swift +++ b/Passepartout-iOS/Global/Product.swift @@ -97,6 +97,18 @@ enum Product: String { // MARK: All static let all: [Product] = allDonations + allFeatures + allProviders + + var isDonation: Bool { + return Product.allDonations.contains(self) + } + + var isFeature: Bool { + return Product.allFeatures.contains(self) + } + + var isProvider: Bool { + return Product.allProviders.contains(self) + } } extension Infrastructure.Name { diff --git a/Passepartout-iOS/Global/ProductManager.swift b/Passepartout-iOS/Global/ProductManager.swift index 9ff50308..34679ec6 100644 --- a/Passepartout-iOS/Global/ProductManager.swift +++ b/Passepartout-iOS/Global/ProductManager.swift @@ -80,6 +80,21 @@ class ProductManager: NSObject { return inApp.product(withIdentifier: identifier) } + func featureProducts(includingFullVersion: Bool) -> [SKProduct] { + return inApp.products.filter { + guard let p = Product(rawValue: $0.productIdentifier) else { + return false + } + guard includingFullVersion || p != .fullVersion else { + return false + } + guard p.isFeature else { + return false + } + return true + } + } + func purchase(_ product: SKProduct, completionHandler: @escaping (InAppPurchaseResult, Error?) -> Void) { inApp.purchase(product: product) { if $0 == .success {