diff --git a/Sources/Earthquake Network/Costanti.h b/Sources/Earthquake Network/Costanti.h index 6c00d30..ba18936 100644 --- a/Sources/Earthquake Network/Costanti.h +++ b/Sources/Earthquake Network/Costanti.h @@ -319,8 +319,6 @@ typedef enum : NSInteger { #define EQN_ACQ_IN_APP @"EQN_ACQ_IN_APP" #define CONTEGGIO_APERTURE_PER_SCONTO @"CONTEGGIO_APERTURE_PER_SCONTO" #define PREZZO_SCONTATO_SCADUTO @"PREZZO_SCONTATO_SCADUTO" -#define AQUISTO_PRO @"com.finazzi.distquake.ProPrezzoPieno" -#define AQUISTO_PRO_SCONTATO @"com.finazzi.distquake.VersioneProScontata" #define IAPHelperPurchaseNotification @"IAPHelperPurchaseNotification" // FILTRO ENTI diff --git a/Sources/Earthquake Network/Models/EQNPurchaseUtility.swift b/Sources/Earthquake Network/Models/EQNPurchaseUtility.swift index 425a6fe..a3cb0f2 100644 --- a/Sources/Earthquake Network/Models/EQNPurchaseUtility.swift +++ b/Sources/Earthquake Network/Models/EQNPurchaseUtility.swift @@ -9,7 +9,8 @@ import Foundation -class EQNPurchaseUtility { +@objc +public class EQNPurchaseUtility: NSObject { private static let AppOpenCountForDiscount = 15 @@ -60,4 +61,15 @@ class EQNPurchaseUtility { } task.resume() } + + /// Check if user has bought pro app version + /// Pro version is enabled also if a yearly subscription is enabled + @objc public static func isProVersionEnabled() -> Bool { + var hasProVersion = false + VersioneProProducts.Identifier.identifierForProVersion.forEach { (identifier) in + hasProVersion = hasProVersion || UserDefaults.standard.bool(forKey: identifier) + } + return hasProVersion + } + } diff --git a/Sources/Earthquake Network/Models/VersioneProProducts.swift b/Sources/Earthquake Network/Models/VersioneProProducts.swift index 83a7e54..1d26a00 100644 --- a/Sources/Earthquake Network/Models/VersioneProProducts.swift +++ b/Sources/Earthquake Network/Models/VersioneProProducts.swift @@ -47,6 +47,12 @@ public struct VersioneProProducts { Subscription10kMonthly, Subscription10kYearly, Subscription10kYearlyDiscounted, Subscription100kMonthly, Subscription100kYearly, Subscription100kYearlyDiscounted ] + + static let identifierForProVersion: Set = [ + ProVersionFullPrice, ProVersionDiscounted, + Subscription10kYearly, Subscription10kYearlyDiscounted, + Subscription100kYearly, Subscription100kYearlyDiscounted + ] } public static let store = IAPHelper(productIds: VersioneProProducts.Identifier.identifiers) diff --git a/Sources/Earthquake Network/ViewController/EQNRetiSismiViewController.m b/Sources/Earthquake Network/ViewController/EQNRetiSismiViewController.m index 791f198..aecfea7 100644 --- a/Sources/Earthquake Network/ViewController/EQNRetiSismiViewController.m +++ b/Sources/Earthquake Network/ViewController/EQNRetiSismiViewController.m @@ -42,10 +42,12 @@ [self aggiornaTabella:nil]; } --(void)setupView{ - - if([[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO] || [[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO_SCONTATO]) - self.fooTable.constant = 0; + +-(void)setupView +{ + if ([EQNPurchaseUtility isProVersionEnabled]) { + self.fooTable.constant = 0; + } } -(void)aggiornaTabella:(id)sender{ diff --git a/Sources/Earthquake Network/ViewController/MasterViewController.m b/Sources/Earthquake Network/ViewController/MasterViewController.m index d6f60dd..e24d61f 100644 --- a/Sources/Earthquake Network/ViewController/MasterViewController.m +++ b/Sources/Earthquake Network/ViewController/MasterViewController.m @@ -110,20 +110,6 @@ } } -- (void)annullaAcquisitiInApp -{ - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - [defaults setBool:NO forKey:AQUISTO_PRO]; - [defaults setBool:NO forKey:AQUISTO_PRO_SCONTATO]; - - [defaults setBool:NO forKey:@"com.finazzi.distquake.Abbonamento10k.mensileAutomatico"]; - [defaults setBool:NO forKey:@"com.finazzi.distquake.Abbonamento10k.annualeAutomatico"]; - [defaults setBool:NO forKey:@"com.finazzi.distquake.Abbonamento10k.annualeAutomaticoScontato"]; - [defaults setBool:NO forKey:@"com.finazzi.distquake.Abbonamento100k.mensileAutomatico"]; - [defaults setBool:NO forKey:@"com.finazzi.distquake.Abbonamento100k.annualeAutomatico"]; - [defaults setBool:NO forKey:@"com.finazzi.distquake.Abbonamento100k.annualeAutomaticoscontato"]; -} - -(void)registraNotifiche{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(apriNotificheSismi) name:NOTIFICHE_SISMI object:nil]; diff --git a/Sources/Earthquake Network/ViewController/ReteSmartphone.m b/Sources/Earthquake Network/ViewController/ReteSmartphone.m index d811ccf..c6708f0 100644 --- a/Sources/Earthquake Network/ViewController/ReteSmartphone.m +++ b/Sources/Earthquake Network/ViewController/ReteSmartphone.m @@ -130,10 +130,9 @@ self.listaItemTableView = [@[@"Allerta sismica",/* NSLocalizedString(@"Dispositivo affidabile", @"item tabelle") ,*/ NSLocalizedString(@"Sismi rilevati da smartphone", @"item tabelle"), NSLocalizedString(@"Rete smartphone", @"item tabelle"), NSLocalizedString(@"Lista priorità - NUOVA!", @"item tabelle"), NSLocalizedString(@"Versione PRO", @"item tabelle"), NSLocalizedString(@"messaggio per utenti", @"item tabelle")] mutableCopy]; - if([[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO] || [[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO_SCONTATO]){ + if ([EQNPurchaseUtility isProVersionEnabled]) { self.fooTable.constant = 0; [self.listaItemTableView removeObject:NSLocalizedString(@"Versione PRO", @"item tabelle")]; - } dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/Sources/Earthquake Network/ViewController/SegnalazioniViewController.m b/Sources/Earthquake Network/ViewController/SegnalazioniViewController.m index 324de6a..ea1d408 100644 --- a/Sources/Earthquake Network/ViewController/SegnalazioniViewController.m +++ b/Sources/Earthquake Network/ViewController/SegnalazioniViewController.m @@ -68,27 +68,13 @@ self.giallo = 0; self.rosso = 0; - /* - for(EQNSegnalazione *segn in [EQNManager defaultManager].elencoSelagnazioniManuali){ - - if ([segn.magnitude intValue] == 1) - self.verde++; - if ([segn.magnitude intValue] == 2) - self.giallo++; - if ([segn.magnitude intValue] == 3) - self.rosso++; - } - */ - - - - if([[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO] || [[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO_SCONTATO]) + if ([EQNPurchaseUtility isProVersionEnabled]) { self.fooTable.constant = 0; + } dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); - } - (void)didReceiveMemoryWarning { diff --git a/Sources/Earthquake Network/ViewController/TsunamiViewController.m b/Sources/Earthquake Network/ViewController/TsunamiViewController.m index 68a5abd..bf81782 100644 --- a/Sources/Earthquake Network/ViewController/TsunamiViewController.m +++ b/Sources/Earthquake Network/ViewController/TsunamiViewController.m @@ -33,10 +33,11 @@ self.listaTsunami = [EQNManager defaultManager].listaTsunami; } --(void)setupView{ - - if([[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO] || [[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO_SCONTATO]) - self.fooTable.constant = 0; +- (void)setupView +{ + if ([EQNPurchaseUtility isProVersionEnabled]) { + self.fooTable.constant = 0; + } } -(void)aggiornaTabella:(id)sender{ diff --git a/Sources/Earthquake Network/model/EQNUtility.m b/Sources/Earthquake Network/model/EQNUtility.m index c9de5fb..d20fa43 100644 --- a/Sources/Earthquake Network/model/EQNUtility.m +++ b/Sources/Earthquake Network/model/EQNUtility.m @@ -370,9 +370,9 @@ } -+(GADBannerView *)ottieniBannerWithController:(UIViewController *)controller position:(BOOL)isButton{ - - if([[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO] || [[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO_SCONTATO]){ ++(GADBannerView *)ottieniBannerWithController:(UIViewController *)controller position:(BOOL)isButton +{ + if ([EQNPurchaseUtility isProVersionEnabled]) { [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:EQN_ACQ_IN_APP]; [[NSUserDefaults standardUserDefaults] synchronize];