comparison GeoQuiz/BuyPremiumModalView.swift @ 13:bdfff35dd43c

implement RevenueCat
author Dennis C. M. <dennis@denniscm.com>
date Wed, 12 Oct 2022 11:47:29 +0200
parents ce7ea84f67f5
children f140bb277c96
comparison
equal deleted inserted replaced
12:ce7ea84f67f5 13:bdfff35dd43c
7 7
8 import SwiftUI 8 import SwiftUI
9 9
10 struct BuyPremiumModalView: View { 10 struct BuyPremiumModalView: View {
11 @Environment(\.dismiss) var dismiss 11 @Environment(\.dismiss) var dismiss
12 @StateObject var storeKitRC = StoreKitRC() 12 @ObservedObject var storeKitRC: StoreKitRC
13 13
14 var body: some View { 14 var body: some View {
15 NavigationView { 15 NavigationView {
16 ScrollView(showsIndicators: false) { 16 ZStack {
17 VStack(alignment: .center, spacing: 20) { 17 ScrollView(showsIndicators: false) {
18 VStack(spacing: 20) { 18 VStack(alignment: .center, spacing: 20) {
19 Text("Unlock Premium 🤩") 19 VStack(spacing: 20) {
20 .font(.largeTitle.bold()) 20 Text("Unlock all games 🤩")
21 21 .font(.largeTitle.bold())
22 Text("Unlock three more game modes to become a geography master and support the future development of GeoQuiz.") 22
23 .foregroundColor(.secondary) 23 Text("Unlock three more game modes to become a geography master and support the future development of GeoQuiz.")
24 .multilineTextAlignment(.center) 24 .foregroundColor(.secondary)
25 .frame(maxWidth: 400) 25 .multilineTextAlignment(.center)
26 } 26 .frame(maxWidth: 400)
27 .padding()
28
29 ScrollView(.horizontal, showsIndicators: false) {
30 HStack(spacing: 20) {
31 Group {
32 Image("GuessTheCapital")
33 .resizable()
34
35 Image("GuessTheCountry")
36 .resizable()
37
38 Image("GuessThePopulation")
39 .resizable()
40 }
41 .scaledToFit()
42 .cornerRadius(25)
43 .frame(height: 500)
44 } 27 }
45 .padding() 28 .padding()
29
30 ScrollView(.horizontal, showsIndicators: false) {
31 HStack(spacing: 20) {
32 Group {
33 Image("GuessTheCapital")
34 .resizable()
35
36 Image("GuessTheCountry")
37 .resizable()
38
39 Image("GuessThePopulation")
40 .resizable()
41 }
42 .scaledToFit()
43 .cornerRadius(25)
44 .frame(height: 500)
45 }
46 .padding()
47 }
48
49 VStack(spacing: 10) {
50 Text("A one-time payment.")
51 .font(.title)
52 .fontWeight(.semibold)
53
54 Text("No subscriptions.")
55 .font(.title2)
56 .fontWeight(.semibold)
57 .foregroundColor(.secondary)
58
59 VStack {
60 if let package = storeKitRC.offerings?.current?.lifetime {
61 Button {
62 storeKitRC.buy(package)
63 } label: {
64 Text("Buy for \(package.storeProduct.localizedPriceString)")
65 .font(.headline)
66 .padding()
67 }
68 .buttonStyle(.borderedProminent)
69 .padding(.top)
70 } else {
71 ProgressView()
72 }
73 }
74
75 Button("Restore purchases", action: storeKitRC.restorePurchase)
76 }
77 .padding()
78
79 VStack {
80 Text("GeoQuiz is an indie game")
81 Text("I appreciate your support ❤️")
82 }
83 .font(.callout)
84 .foregroundColor(.secondary)
85 .padding()
46 } 86 }
47 87 }
48 VStack(spacing: 10) { 88
49 Text("A one-time payment.") 89 if storeKitRC.showingActivityAlert {
50 .font(.title) 90 ActivityAlert()
51 .fontWeight(.semibold)
52
53 Text("No subscriptions.")
54 .font(.title2)
55 .fontWeight(.semibold)
56 .foregroundColor(.secondary)
57
58 if let productPrice = storeKitRC.productPrice {
59 Button {
60 // Buy
61 } label: {
62 Text("Buy for \(productPrice)")
63 .font(.headline)
64 .padding()
65 }
66 .buttonStyle(.borderedProminent)
67 .padding(.top)
68 } else {
69 ProgressView()
70 .padding(.top)
71 }
72 }
73 .padding()
74
75 VStack {
76 Text("GeoQuiz is an indie game")
77 Text("I appreciate your support ❤️")
78 }
79 .font(.callout)
80 .foregroundColor(.secondary)
81 .padding()
82 } 91 }
83 } 92 }
84 .navigationBarTitleDisplayMode(.inline) 93 .navigationBarTitleDisplayMode(.inline)
94 .onAppear(perform: storeKitRC.fetchOfferings)
85 .toolbar { 95 .toolbar {
86 ToolbarItem(placement: .cancellationAction) { 96 ToolbarItem(placement: .cancellationAction) {
87 Button { 97 Button {
88 dismiss() 98 dismiss()
89 } label: { 99 } label: {
90 Label("Exit", systemImage: "multiply") 100 Label("Exit", systemImage: "multiply")
91 } 101 }
92 } 102 }
93 } 103 }
94 .alert("Something went wrong 🤕", isPresented: $storeKitRC.showingErrorAlert) { 104 }
95 Button("OK", role: .cancel) { dismiss() } 105 .disabled(storeKitRC.showingActivityAlert)
96 } message: { 106 .interactiveDismissDisabled(storeKitRC.showingActivityAlert)
97 Text(storeKitRC.errorMessage) 107
98 } 108 .alert(storeKitRC.errorAlertTitle, isPresented: $storeKitRC.showingErrorAlert) {
109 Button("OK", role: .cancel) { }
110 } message: {
111 Text(storeKitRC.errorAlertMessage)
112 }
113
114 .alert("GeoQuiz Premium is active!", isPresented: $storeKitRC.showingSuccessAlert) {
115 Button("OK", role: .cancel) { dismiss() }
116 } message: {
117 Text("Thanks for supporting indie apps ❤️")
99 } 118 }
100 } 119 }
101 } 120 }
102 121
103 struct BuyPremiumModalView_Previews: PreviewProvider { 122 struct BuyPremiumModalView_Previews: PreviewProvider {
104 static var previews: some View { 123 static var previews: some View {
105 BuyPremiumModalView() 124 BuyPremiumModalView(storeKitRC: StoreKitRC())
106 } 125 }
107 } 126 }