Mercurial > public > geoquiz
diff GeoQuiz/Logic/StoreKitRCClass.swift @ 12:ce7ea84f67f5
display product prices
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Sun, 09 Oct 2022 19:46:44 +0200 |
parents | |
children | bdfff35dd43c |
line wrap: on
line diff
--- /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 + } + } + } +}