refactor: Create constants for IAP and use them instead of fixed identifiers

This commit is contained in:
Andrea Busi
2020-07-25 10:36:38 +02:00
parent 5c07d59ea4
commit ff2b1a6d00
5 changed files with 64 additions and 114 deletions
@@ -60,45 +60,28 @@ class AbbonamentiViewController: UIViewController, UITableViewDataSource, UITabl
if let prodotto = anProdotto{
if VersioneProProducts.store.isProductPurchased(prodotto.productIdentifier) {
descrizione.isHidden = true
switch prodotto.productIdentifier{
case "com.finazzi.distquake.Abbonamento10k.annualeAutomatico", "com.finazzi.distquake.Abbonamento10k.annualeAutomaticoScontato":
switch prodotto.productIdentifier {
case VersioneProProducts.Identifier.Subscription10kYearly, VersioneProProducts.Identifier.Subscription10kYearlyDiscounted:
immagine.image = UIImage.init(named: "top_10k")
self.descrizione.text = NSLocalizedString("Sei abbonato: priorità 10000 persone, rinnovo annuale ", comment: "")
break
case "com.finazzi.distquake.Abbonamento10k.mensileAutomatico" :
case VersioneProProducts.Identifier.Subscription10kMonthly:
immagine.image = UIImage.init(named: "top_10k")
self.tiolo.text = NSLocalizedString("Sei abbonato: priorità 10000 persone, rinnovo mensile ", comment: "")
break
case "com.finazzi.distquake.Abbonamento100k.annualeAutomatico",
"com.finazzi.distquake.Abbonamento100k.annualeAutomaticoscontato":
case VersioneProProducts.Identifier.Subscription100kYearly, VersioneProProducts.Identifier.Subscription100kYearlyDiscounted:
immagine.image = UIImage.init(named: "top_100k")
self.tiolo.text = NSLocalizedString("Sei abbonato: priorità 100000 persone, rinnovo annuale ", comment: "")
break
case "com.finazzi.distquake.Abbonamento100k.mensileAutomatico" :
case VersioneProProducts.Identifier.Subscription100kMonthly:
immagine.image = UIImage.init(named: "top_100k")
self.tiolo.text = NSLocalizedString("Sei abbonato: priorità 100000 persone, rinnovo mensile ", comment: "")
break
default:
break
}
self.dettaglioAcquisto.text = NSLocalizedString("• L'abbonamento si rinnova automaticamente a meno che il rinnovo automatico non venga disattivato almeno 24 ore prima della fine del periodo corrente\n\n• L'abbonamento verrà addebitato per il rinnovo entro 24 ore prima della fine del periodo corrente e identificato il costo del rinnovo\n\n• Le sottoscrizioni possono essere gestite dall'utente e il rinnovo automatico può essere disattivato accedendo alle Impostazioni account dell'utente dopo l'acquisto.\n\n", comment: "")
@@ -128,46 +111,29 @@ class AbbonamentiViewController: UIViewController, UITableViewDataSource, UITabl
guard let self = self else { return }
if success {
for prodoct in products!{
if VersioneProProducts.store.isProductPurchased(prodoct.productIdentifier) {
self.isAcquisto = true
self.anProdotto = prodoct
self.aggirnaView()
}else{
} else {
if self.checkDiscount() {
if prodoct.productIdentifier == "com.finazzi.distquake.Abbonamento10k.mensileAutomatico" ||
prodoct.productIdentifier == "com.finazzi.distquake.Abbonamento100k.mensileAutomatico" {
if prodoct.productIdentifier == VersioneProProducts.Identifier.Subscription10kMonthly ||
prodoct.productIdentifier == VersioneProProducts.Identifier.Subscription100kMonthly {
self.productsMensile.append(prodoct)
} else if prodoct.productIdentifier == "com.finazzi.distquake.Abbonamento10k.annualeAutomaticoScontato" ||
prodoct.productIdentifier == "com.finazzi.distquake.Abbonamento100k.annualeAutomaticoscontato"
{
} else if prodoct.productIdentifier == VersioneProProducts.Identifier.Subscription10kYearlyDiscounted ||
prodoct.productIdentifier == VersioneProProducts.Identifier.Subscription100kYearlyDiscounted {
self.productsAnnuale.append(prodoct)
}
}else{
if prodoct.productIdentifier == "com.finazzi.distquake.Abbonamento10k.mensileAutomatico" ||
prodoct.productIdentifier == "com.finazzi.distquake.Abbonamento100k.mensileAutomatico"{
} else {
if prodoct.productIdentifier == VersioneProProducts.Identifier.Subscription10kMonthly ||
prodoct.productIdentifier == VersioneProProducts.Identifier.Subscription100kMonthly {
self.productsMensile.append(prodoct)
}
else if
prodoct.productIdentifier == "com.finazzi.distquake.Abbonamento10k.annualeAutomatico" ||
prodoct.productIdentifier == "com.finazzi.distquake.Abbonamento100k.annualeAutomatico"
{
else if prodoct.productIdentifier == VersioneProProducts.Identifier.Subscription10kYearly ||
prodoct.productIdentifier == VersioneProProducts.Identifier.Subscription100kYearly {
self.productsAnnuale.append(prodoct)
}
}
}
}
@@ -49,44 +49,35 @@ class AcquistiProViewController: UIViewController {
pulsanteAcquista.isEnabled = false
VersioneProProducts.store.requestProducts{ [weak self] success, products in
guard let self = self else { return }
guard let self = self, let products = products else { return }
if success {
self.products = products!
for prodoct in self.products{
if self.checkDiscount() {
if prodoct.productIdentifier == "com.finazzi.distquake.ProPrezzoPieno"{
self.prodotto = prodoct
}
}else{
if prodoct.productIdentifier == "com.finazzi.distquake.VersioneProScontata"{
self.prodotto = prodoct
}
}
}
self.products = products
// self.prezzolabel.text = self.prodotto.price
for product in self.products {
if self.checkDiscount() {
if product.productIdentifier.lowercased() == VersioneProProducts.Identifier.ProVersionFullPrice.lowercased() {
self.prodotto = product
}
} else {
if product.productIdentifier.lowercased() == VersioneProProducts.Identifier.ProVersionDiscounted.lowercased() {
self.prodotto = product
}
}
}
AcquistiProViewController.priceFormatter.locale = self.prodotto.priceLocale
self.prezzolabel.text = AcquistiProViewController.priceFormatter.string(from: self.prodotto.price)
self.pulsanteAcquista.isEnabled = true
self.titoloSconto.text = NSLocalizedString("Stai acquistando la verisone pro, verrà rimossa la pubblicità", comment: "")
if UserDefaults.standard.bool(forKey: "com.finazzi.distquake.ProPrezzoPieno") ||
UserDefaults.standard.bool(forKey: "com.finazzi.distquake.VersioneProScontata") ||
UserDefaults.standard.bool(forKey:"com.finazzi.distquake.Abbonamento10k.annualeAutomatico") ||
UserDefaults.standard.bool(forKey: "com.finazzi.distquake.Abbonamento10k.annualeAutomaticoScontato") ||
UserDefaults.standard.bool(forKey: "com.finazzi.distquake.Abbonamento100k.annualeAutomatico") ||
UserDefaults.standard.bool(forKey: "com.finazzi.distquake.Abbonamento100k.annualeAutomaticoscontato") {
if UserDefaults.standard.bool(forKey: VersioneProProducts.Identifier.ProVersionFullPrice) ||
UserDefaults.standard.bool(forKey: VersioneProProducts.Identifier.ProVersionDiscounted) ||
UserDefaults.standard.bool(forKey: VersioneProProducts.Identifier.Subscription10kYearly) ||
UserDefaults.standard.bool(forKey: VersioneProProducts.Identifier.Subscription10kYearlyDiscounted) ||
UserDefaults.standard.bool(forKey: VersioneProProducts.Identifier.Subscription100kYearly) ||
UserDefaults.standard.bool(forKey: VersioneProProducts.Identifier.Subscription100kYearlyDiscounted) {
self.pulsanteAcquista.isEnabled = false
self.prezzolabel.text = ""
}
}
@@ -43,44 +43,33 @@ class DettagliAbbonamentoViewController: UIViewController {
self.linkTextView.text = NSLocalizedString("Privacy: http://wp.earthquakenetwork.it/privacy/\n\nTermini e condizioni: http://wp.earthquakenetwork.it/it/terms-conditions/", comment: "")
// Do any additional setup after loading the view.
var personeAllertate : NSString
switch prodotto.productIdentifier{
switch prodotto.productIdentifier {
case "com.finazzi.distquake.Abbonamento10k.mensileAutomatico":
case VersioneProProducts.Identifier.Subscription10kMonthly:
immagine.image = UIImage.init(named: "top_10k")
titolo.text = NSLocalizedString("Abbonamento mensile, priorità 10000 persone ", comment: "")
labelPagamento.text = self.prodotto.localizedTitle + ",\n" + NSLocalizedString("pagerai al mese:", comment: "")
personeAllertate = NSLocalizedString(" 10000 persone allertate.", comment: "") as NSString
break
case "com.finazzi.distquake.Abbonamento100k.mensileAutomatico" :
case VersioneProProducts.Identifier.Subscription100kMonthly:
immagine.image = UIImage.init(named: "top_100k")
titolo.text = NSLocalizedString("Abbonamento mensile, priorità 100000 persone ", comment: "")
labelPagamento.text = self.prodotto.localizedTitle + ",\n" + NSLocalizedString("pagerai al mese:", comment: "")
personeAllertate = NSLocalizedString(" 100000 persone allertate.", comment: "") as NSString
break
case "com.finazzi.distquake.Abbonamento100k.annualeAutomatico", "com.finazzi.distquake.Abbonamento100k.annualeAutomaticoscontato":
case VersioneProProducts.Identifier.Subscription100kYearly, VersioneProProducts.Identifier.Subscription100kYearlyDiscounted:
immagine.image = UIImage.init(named: "top_100k")
titolo.text = NSLocalizedString("Abbonamento annuale, priorità 100000 persone ", comment: "")
labelPagamento.text = self.prodotto.localizedTitle + ",\n" + NSLocalizedString("pagerai all'anno:", comment: "")
personeAllertate = NSLocalizedString(" 100000 persone allertate.", comment: "") as NSString
break
case "com.finazzi.distquake.Abbonamento10k.annualeAutomatico", "com.finazzi.distquake.Abbonamento10k.annualeAutomaticoScontato":
case VersioneProProducts.Identifier.Subscription10kYearly, VersioneProProducts.Identifier.Subscription10kYearlyDiscounted:
immagine.image = UIImage.init(named: "top_10k")
titolo.text = NSLocalizedString("Abbonamento annuale, priorità 10000 persone ", comment: "")
labelPagamento.text = self.prodotto.localizedTitle + ",\n" + NSLocalizedString("pagerai all'anno:", comment: "")
personeAllertate = NSLocalizedString(" 10000 persone allertate.", comment: "") as NSString
break
default:
personeAllertate = NSLocalizedString(" 10000 persone allertate.", comment: "") as NSString
@@ -66,9 +66,9 @@ class ProductCell: UITableViewCell {
self.titolo?.text = product.localizedTitle
self.sottoscrivibutton.setTitle( NSLocalizedString("DETTAGLI", comment: "pulsante abbonamenti"), for: .normal)
if product.productIdentifier == "com.finazzi.distquake.Abbonamento100k.mensileAutomatico" ||
product.productIdentifier == "com.finazzi.distquake.Abbonamento100k.annualeAutomaticoscontato" ||
product.productIdentifier == "com.finazzi.distquake.Abbonamento100k.annualeAutomatico"{
if product.productIdentifier == VersioneProProducts.Identifier.Subscription100kMonthly ||
product.productIdentifier == VersioneProProducts.Identifier.Subscription100kYearlyDiscounted ||
product.productIdentifier == VersioneProProducts.Identifier.Subscription100kYearly {
self.immagine.image = UIImage.init(named: "top_100k")
@@ -30,22 +30,26 @@ import Foundation
public struct VersioneProProducts {
public static let SwiftShopping1 = "com.finazzi.distquake.ProPrezzoPieno"
public static let SwiftShopping2 = "com.finazzi.distquake.VersioneProScontata"
public static let SwiftShopping4 = "com.finazzi.distquake.Abbonamento10k.mensileAutomatico"
public static let SwiftShopping = "com.finazzi.distquake.Abbonamento10k.annualeAutomatico"
public static let SwiftShopping3 = "com.finazzi.distquake.Abbonamento10k.annualeAutomaticoScontato"
public static let SwiftShopping7 = "com.finazzi.distquake.Abbonamento100k.mensileAutomatico"
public static let SwiftShopping5 = "com.finazzi.distquake.Abbonamento100k.annualeAutomatico"
public static let SwiftShopping6 = "com.finazzi.distquake.Abbonamento100k.annualeAutomaticoscontato"
public enum Identifier {
static let ProVersionFullPrice = "com.finazzi.distquake.ProPrezzoPieno"
static let ProVersionDiscounted = "com.finazzi.distquake.VersioneProScontata"
static let Subscription10kMonthly = "com.finazzi.distquake.Abbonamento10k.mensileAutomatico"
static let Subscription10kYearly = "com.finazzi.distquake.Abbonamento10k.annualeAutomatico"
static let Subscription10kYearlyDiscounted = "com.finazzi.distquake.Abbonamento10k.annualeAutomaticoScontato"
static let Subscription100kMonthly = "com.finazzi.distquake.Abbonamento100k.mensileAutomatico"
static let Subscription100kYearly = "com.finazzi.distquake.Abbonamento100k.annualeAutomatico"
static let Subscription100kYearlyDiscounted = "com.finazzi.distquake.Abbonamento100k.annualeAutomaticoscontato"
static let identifiers: Set<ProductIdentifier> = [
ProVersionFullPrice, ProVersionDiscounted,
Subscription10kMonthly, Subscription10kYearly, Subscription10kYearlyDiscounted,
Subscription100kMonthly, Subscription100kYearly, Subscription100kYearlyDiscounted
]
}
// com.finazzi.distquake.AbbonamentoAnnuale.scontato
private static let productIdentifiers: Set<ProductIdentifier> = [VersioneProProducts.SwiftShopping, VersioneProProducts.SwiftShopping1, VersioneProProducts.SwiftShopping2, VersioneProProducts.SwiftShopping3, VersioneProProducts.SwiftShopping4, VersioneProProducts.SwiftShopping5, VersioneProProducts.SwiftShopping6, VersioneProProducts.SwiftShopping7]
public static let store = IAPHelper(productIds: VersioneProProducts.productIdentifiers)
public static let store = IAPHelper(productIds: VersioneProProducts.Identifier.identifiers)
}
func resourceNameForProductIdentifier(_ productIdentifier: String) -> String? {