|
|
|
@ -14,12 +14,12 @@ class PurchaseManager: ObservableObject { |
|
|
|
static let main: PurchaseManager = PurchaseManager() |
|
|
|
static let main: PurchaseManager = PurchaseManager() |
|
|
|
|
|
|
|
|
|
|
|
fileprivate var _products: [Product] = [] |
|
|
|
fileprivate var _products: [Product] = [] |
|
|
|
fileprivate var _purchases: [Purchase] = [] |
|
|
|
// fileprivate var _purchases: [Purchase] = [] |
|
|
|
|
|
|
|
|
|
|
|
@Published var purchaseRows: [PurchaseRow] = [] |
|
|
|
@Published var purchaseRows: [PurchaseRow] = [] |
|
|
|
|
|
|
|
|
|
|
|
init() { |
|
|
|
init() { |
|
|
|
// NotificationCenter.default.addObserver(self, selector: #selector(_purchasesChanged(notification:)), name: NSNotification.Name.CollectionDidChange, object: Guard.main.purchases) |
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(_purchasesChanged(notification:)), name: NSNotification.Name.StoreEventHappened, object: nil) |
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(_purchasesChanged(notification:)), name: NSNotification.Name.StoreEventHappened, object: nil) |
|
|
|
|
|
|
|
|
|
|
|
let identifiers: [String] = StoreItem.allCases.map { $0.rawValue } |
|
|
|
let identifiers: [String] = StoreItem.allCases.map { $0.rawValue } |
|
|
|
@ -34,11 +34,6 @@ class PurchaseManager: ObservableObject { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@objc fileprivate func _purchasesChanged(notification: Notification) { |
|
|
|
@objc fileprivate func _purchasesChanged(notification: Notification) { |
|
|
|
guard let collection = notification.object as? StoredCollection<Purchase> else { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
self._purchases.removeAll() |
|
|
|
|
|
|
|
self._purchases.append(contentsOf: collection) |
|
|
|
|
|
|
|
self._buildRowsOnMainThread() |
|
|
|
self._buildRowsOnMainThread() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -64,21 +59,6 @@ class PurchaseManager: ObservableObject { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Subscriptions |
|
|
|
|
|
|
|
// for userPurchase in userPurchases { |
|
|
|
|
|
|
|
// print("from = \(userPurchase.purchaseDate) / to = \(userPurchase.expirationDate)") |
|
|
|
|
|
|
|
// if let item = StoreItem(rawValue: userPurchase.productID), |
|
|
|
|
|
|
|
// let product = self._products.first(where: { $0.id == item.rawValue } ) { |
|
|
|
|
|
|
|
// switch item { |
|
|
|
|
|
|
|
// case .fivePerMonth, .monthlyUnlimited: |
|
|
|
|
|
|
|
// rows.append(PurchaseRow(id: userPurchase.originalID, name: product.displayName, item: item)) |
|
|
|
|
|
|
|
// case .unit: |
|
|
|
|
|
|
|
// break |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Units |
|
|
|
// Units |
|
|
|
let remainingTournaments = Guard.main.remainingTournaments |
|
|
|
let remainingTournaments = Guard.main.remainingTournaments |
|
|
|
if remainingTournaments > 0 { |
|
|
|
if remainingTournaments > 0 { |
|
|
|
@ -88,6 +68,8 @@ class PurchaseManager: ObservableObject { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.log("purchases = \(rows)") |
|
|
|
|
|
|
|
|
|
|
|
self.purchaseRows = rows |
|
|
|
self.purchaseRows = rows |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -123,7 +105,7 @@ struct PurchaseView: View { |
|
|
|
var body: some View { |
|
|
|
var body: some View { |
|
|
|
HStack { |
|
|
|
HStack { |
|
|
|
Image(systemName: self.purchaseRow.item.systemImage) |
|
|
|
Image(systemName: self.purchaseRow.item.systemImage) |
|
|
|
.foregroundColor(.accentColor) |
|
|
|
.foregroundColor(.accentColor).font(.title2) |
|
|
|
Text(self.purchaseRow.name) |
|
|
|
Text(self.purchaseRow.name) |
|
|
|
Spacer() |
|
|
|
Spacer() |
|
|
|
if let _ = purchaseRow.quantity { |
|
|
|
if let _ = purchaseRow.quantity { |
|
|
|
|