# HG changeset patch # User Dennis C. M. # Date 1665337604 -7200 # Node ID ce7ea84f67f562a1c3ccd65dbd2dc75b17fb70c8 # Parent 039b26a99a48a24a260e42ce6358ab96cfe0619b display product prices diff -r 039b26a99a48 -r ce7ea84f67f5 GeoQuiz.xcodeproj/project.pbxproj --- a/GeoQuiz.xcodeproj/project.pbxproj Sun Oct 09 17:02:34 2022 +0200 +++ b/GeoQuiz.xcodeproj/project.pbxproj Sun Oct 09 19:46:44 2022 +0200 @@ -13,6 +13,7 @@ 950C535328F2FA3300179C78 /* BuyPremiumModalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950C535228F2FA3300179C78 /* BuyPremiumModalView.swift */; }; 950C535628F3172C00179C78 /* RevenueCat in Frameworks */ = {isa = PBXBuildFile; productRef = 950C535528F3172C00179C78 /* RevenueCat */; }; 950C535928F3178B00179C78 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 950C535828F3178B00179C78 /* StoreKit.framework */; }; + 95197EFD28F339AE00FE67E9 /* StoreKitRCClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95197EFC28F339AE00FE67E9 /* StoreKitRCClass.swift */; }; 951AFAEA28E5655C00A4A4BD /* cities.json in Resources */ = {isa = PBXBuildFile; fileRef = 951AFAE828E5655C00A4A4BD /* cities.json */; }; 951AFAED28E5657500A4A4BD /* CityModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951AFAEC28E5657500A4A4BD /* CityModel.swift */; }; 951AFAEF28E565FE00A4A4BD /* CountryModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951AFAEE28E565FE00A4A4BD /* CountryModel.swift */; }; @@ -51,6 +52,7 @@ 9509A8E128E5A3D700CFCDBA /* GuessThePopulationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuessThePopulationView.swift; sourceTree = ""; }; 950C535228F2FA3300179C78 /* BuyPremiumModalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuyPremiumModalView.swift; sourceTree = ""; }; 950C535828F3178B00179C78 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; + 95197EFC28F339AE00FE67E9 /* StoreKitRCClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKitRCClass.swift; sourceTree = ""; }; 951AFAE828E5655C00A4A4BD /* cities.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = cities.json; sourceTree = ""; }; 951AFAEC28E5657500A4A4BD /* CityModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CityModel.swift; sourceTree = ""; }; 951AFAEE28E565FE00A4A4BD /* CountryModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountryModel.swift; sourceTree = ""; }; @@ -109,6 +111,7 @@ 95FA409B28D9881100129B60 /* CountryGameClass.swift */, 951AFAF028E5735400A4A4BD /* CityGameClass.swift */, 95919DB528F076BF00F21F8F /* UserClass.swift */, + 95197EFC28F339AE00FE67E9 /* StoreKitRCClass.swift */, 95AE8D5628C8750E0067F219 /* LoadFunc.swift */, ); path = Logic; @@ -280,6 +283,7 @@ 955A65A928D7815E00CEEC6D /* HapticsClass.swift in Sources */, 95BC392D28EC42570049AB49 /* CityMapHelper.swift in Sources */, 952E41E928DC521200198643 /* GameAlertsModifier.swift in Sources */, + 95197EFD28F339AE00FE67E9 /* StoreKitRCClass.swift in Sources */, 95919DB828F079D100F21F8F /* UserSettingsModel.swift in Sources */, 9509A8E228E5A3D700CFCDBA /* GuessThePopulationView.swift in Sources */, 955A658328D733E400CEEC6D /* GameProtocol+Extension.swift in Sources */, diff -r 039b26a99a48 -r ce7ea84f67f5 GeoQuiz/BuyPremiumModalView.swift --- a/GeoQuiz/BuyPremiumModalView.swift Sun Oct 09 17:02:34 2022 +0200 +++ b/GeoQuiz/BuyPremiumModalView.swift Sun Oct 09 19:46:44 2022 +0200 @@ -9,6 +9,7 @@ struct BuyPremiumModalView: View { @Environment(\.dismiss) var dismiss + @StateObject var storeKitRC = StoreKitRC() var body: some View { NavigationView { @@ -54,15 +55,20 @@ .fontWeight(.semibold) .foregroundColor(.secondary) - Button { - // Buy - } label: { - Text("Buy for $2.99") - .font(.headline) - .padding() + if let productPrice = storeKitRC.productPrice { + Button { + // Buy + } label: { + Text("Buy for \(productPrice)") + .font(.headline) + .padding() + } + .buttonStyle(.borderedProminent) + .padding(.top) + } else { + ProgressView() + .padding(.top) } - .buttonStyle(.borderedProminent) - .padding(.top) } .padding() @@ -72,6 +78,7 @@ } .font(.callout) .foregroundColor(.secondary) + .padding() } } .navigationBarTitleDisplayMode(.inline) @@ -84,6 +91,11 @@ } } } + .alert("Something went wrong šŸ¤•", isPresented: $storeKitRC.showingErrorAlert) { + Button("OK", role: .cancel) { dismiss() } + } message: { + Text(storeKitRC.errorMessage) + } } } } diff -r 039b26a99a48 -r ce7ea84f67f5 GeoQuiz/GeoQuizApp.swift --- a/GeoQuiz/GeoQuizApp.swift Sun Oct 09 17:02:34 2022 +0200 +++ b/GeoQuiz/GeoQuizApp.swift Sun Oct 09 19:46:44 2022 +0200 @@ -18,16 +18,6 @@ var body: some Scene { WindowGroup { ContentView() - .onAppear(perform: testRevenueCat) - } - } - - private func testRevenueCat() { - Purchases.shared.getOfferings { (offerings, error) in - if let packages = offerings?.current?.availablePackages { - // Display packages for sale - print(packages) - } } } } diff -r 039b26a99a48 -r ce7ea84f67f5 GeoQuiz/Info.plist --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GeoQuiz/Info.plist Sun Oct 09 19:46:44 2022 +0200 @@ -0,0 +1,10 @@ + + + + + UIBackgroundModes + + audio + + + diff -r 039b26a99a48 -r ce7ea84f67f5 GeoQuiz/Logic/StoreKitRCClass.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GeoQuiz/Logic/StoreKitRCClass.swift Sun Oct 09 19:46:44 2022 +0200 @@ -0,0 +1,33 @@ +// +// StoreKitRCClass.swift +// GeoQuiz +// +// Created by Dennis Concepción MartĆ­n on 9/10/22. +// + +import Foundation +import RevenueCat + +class StoreKitRC: ObservableObject { + @Published var productPrice: String? + @Published var showingErrorAlert = false + @Published var errorMessage = "" + + init() { + + // Get product metadata + Purchases.shared.getOfferings { (offerings, error) in + if let package = offerings?.current?.lifetime?.storeProduct { + self.productPrice = package.localizedPriceString + } else { + self.errorMessage = "There was an error fetching the product. Please, contact the developer at dmartin@dennistech.io." + self.showingErrorAlert = true + } + + if let error = error { + self.errorMessage = error.localizedDescription + self.showingErrorAlert = true + } + } + } +}