Fixes in the subscription process

main
Laurent 3 years ago
parent 51057f3fcb
commit 74b1092680
  1. 12
      LeCountdown/Subscription/AppGuard.swift
  2. 1
      LeCountdown/Subscription/Store.swift
  3. 49
      LeCountdown/Subscription/StoreView.swift
  4. 2
      LeCountdown/Views/ContentView.swift
  5. 2
      LeCountdown/Views/PresetsView.swift
  6. 1
      LeCountdown/fr.lproj/Localizable.strings

@ -36,7 +36,7 @@ extension Notification.Name {
@Published private(set) var purchasedTransactions = Set<StoreKit.Transaction>() @Published private(set) var purchasedTransactions = Set<StoreKit.Transaction>()
var currentBestPlan: StoreKit.Transaction? = nil @Published var currentBestPlan: StoreKit.Transaction? = nil
var updateListenerTask: Task<Void, Error>? = nil var updateListenerTask: Task<Void, Error>? = nil
@ -124,20 +124,20 @@ extension Notification.Name {
} }
var isSubscriber: Bool { var isSubscriber: Bool {
return false // self.currentPlan != .none return self.currentPlan != .none
} }
var currentPlan: StorePlan { var currentPlan: StorePlan {
#if DEBUG // #if DEBUG
return .yearly // return .yearly
#else // #else
if let currentBestPlan = self.currentBestPlan, if let currentBestPlan = self.currentBestPlan,
let plan = StorePlan(rawValue: currentBestPlan.productID) { let plan = StorePlan(rawValue: currentBestPlan.productID) {
return plan return plan
} }
return .none return .none
#endif // #endif
} }
fileprivate func _updateBestPlan() { fileprivate func _updateBestPlan() {

@ -87,6 +87,7 @@ class Store: ObservableObject {
await transaction.finish() await transaction.finish()
DispatchQueue.main.asyncAfter(deadline: DispatchTime(uptimeNanoseconds: 200000), execute: { DispatchQueue.main.asyncAfter(deadline: DispatchTime(uptimeNanoseconds: 200000), execute: {
Conductor.maestro.playSound(Sound.EX_ATSM_140_Koshi_Chimes_Aria_Tuning_Loop_Wondering_Am)
NotificationCenter.default.post(name: Notification.Name.StoreEventHappened, object: nil) NotificationCenter.default.post(name: Notification.Name.StoreEventHappened, object: nil)
}) })

@ -29,15 +29,17 @@ fileprivate enum Feature: Int, Identifiable, CaseIterable {
struct StoreView: View, StoreDelegate { struct StoreView: View, StoreDelegate {
@StateObject var store: Store = Store() @StateObject private var store: Store = Store()
@State var errorMessage: String? = nil @State private var errorMessage: String? = nil
@Binding var isPresented: Bool
var body: some View { var body: some View {
Group { Group {
if !self.store.products.isEmpty { if !self.store.products.isEmpty {
PlanView() PlanView(isPresented: self.$isPresented)
.environmentObject(self.store) .environmentObject(self.store)
} else { } else {
ProgressView() ProgressView()
@ -69,9 +71,11 @@ struct PlanView: View {
@EnvironmentObject var store: Store @EnvironmentObject var store: Store
// var productName: String @State var _loadingProduct: String? = nil
// var price: String @State var _purchased: Bool = false
@Binding var isPresented: Bool
var body: some View { var body: some View {
VStack { VStack {
@ -107,17 +111,26 @@ struct PlanView: View {
} label: { } label: {
HStack { HStack {
Spacer() Spacer()
VStack {
if product.id == self._loadingProduct {
if let plan = StorePlan(rawValue: product.id) { if self._purchased {
Text("\(product.displayPrice) / \(plan.formattedPeriod)").font(.title3) Image(systemName: "checkmark.circle.fill")
} else { } else {
Text("Plan not found") ProgressView()
.progressViewStyle(.circular).tint(.white)
}
} else {
VStack {
if let plan = StorePlan(rawValue: product.id) {
Text("\(product.displayPrice) / \(plan.formattedPeriod)").font(.title3)
} else {
Text("Plan not found")
}
} }
} }
Spacer() Spacer()
} }.frame(height: 44.0)
} }
.buttonStyle(.borderedProminent) .buttonStyle(.borderedProminent)
.fontWeight(.medium) .fontWeight(.medium)
@ -128,7 +141,15 @@ struct PlanView: View {
fileprivate func _purchase(product: Product) { fileprivate func _purchase(product: Product) {
Task { Task {
try await store.purchase(product) self._loadingProduct = product.id
let result = try await store.purchase(product)
switch result {
case .none:
self._loadingProduct = nil
case .some:
self._purchased = true
self.isPresented = false
}
} }
} }
@ -192,6 +213,6 @@ struct PlayerWrapperView: View {
struct StoreView_Previews: PreviewProvider { struct StoreView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
PlanView().environmentObject(Store()) PlanView(isPresented: .constant(false)).environmentObject(Store())
} }
} }

@ -114,7 +114,7 @@ struct ContentView<T : AbstractTimer>: View {
.presentationDetents([.height(240.0)]) .presentationDetents([.height(240.0)])
}) })
.sheet(isPresented: self.$showSubscriptionSheet, content: { .sheet(isPresented: self.$showSubscriptionSheet, content: {
StoreView() StoreView(isPresented: self.$showSubscriptionSheet)
}) })
.toolbar { .toolbar {
ToolbarItem(placement: .navigationBarLeading) { ToolbarItem(placement: .navigationBarLeading) {

@ -113,7 +113,7 @@ struct PresetsView: View {
.environment(\.managedObjectContext, viewContext) .environment(\.managedObjectContext, viewContext)
}) })
.sheet(isPresented: $isShowingSubscription, content: { .sheet(isPresented: $isShowingSubscription, content: {
StoreView() StoreView(isPresented: self.$isShowingSubscription)
}) })
.navigationTitle("Create") .navigationTitle("Create")
} }

@ -257,3 +257,4 @@
"Confirmation" = "Confirmation"; "Confirmation" = "Confirmation";
"month" = "mois"; "month" = "mois";
"year" = "an"; "year" = "an";
"Get fully enchanted" = "Enchantement permanent";

Loading…
Cancel
Save