Iterate feature-based products

This commit is contained in:
Davide De Rosa 2019-11-09 17:32:00 +01:00
parent 1ed4d32d5d
commit 63bd33aa4e
2 changed files with 27 additions and 0 deletions

View File

@ -97,6 +97,18 @@ enum Product: String {
// MARK: All // MARK: All
static let all: [Product] = allDonations + allFeatures + allProviders 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 { extension Infrastructure.Name {

View File

@ -80,6 +80,21 @@ class ProductManager: NSObject {
return inApp.product(withIdentifier: identifier) 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) { func purchase(_ product: SKProduct, completionHandler: @escaping (InAppPurchaseResult, Error?) -> Void) {
inApp.purchase(product: product) { inApp.purchase(product: product) {
if $0 == .success { if $0 == .success {