|
|
|
|
@ -19,7 +19,8 @@ class PurchaseManager: ObservableObject { |
|
|
|
|
@Published var purchaseRows: [PurchaseRow] = [] |
|
|
|
|
|
|
|
|
|
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.CollectionDidChange, object: Guard.main.purchases) |
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(_purchasesChanged(notification:)), name: NSNotification.Name.StoreEventHappened, object: nil) |
|
|
|
|
|
|
|
|
|
let identifiers: [String] = StoreItem.allCases.map { $0.rawValue } |
|
|
|
|
Task { |
|
|
|
|
@ -54,20 +55,30 @@ class PurchaseManager: ObservableObject { |
|
|
|
|
var rows: [PurchaseRow] = [] |
|
|
|
|
let userPurchases: [StoreKit.Transaction] = Guard.main.userFilteredPurchases() |
|
|
|
|
|
|
|
|
|
// Subscriptions |
|
|
|
|
for userPurchase in userPurchases { |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|
let subscriptions: [StoreItem] = StoreItem.allCases.filter { !$0.isConsumable } |
|
|
|
|
for subscription in subscriptions { |
|
|
|
|
|
|
|
|
|
if let userPurchase = userPurchases.first(where: { $0.productID == subscription.rawValue }), let product = self._products.first(where: { $0.id == subscription.rawValue }) { |
|
|
|
|
|
|
|
|
|
rows.append(PurchaseRow(id: userPurchase.originalID, name: product.displayName, item: subscription)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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 |
|
|
|
|
let remainingTournaments = Guard.main.remainingTournaments |
|
|
|
|
if remainingTournaments > 0 { |
|
|
|
|
|