refactor: Create a common method to check for a pro version enabled
Pro version is enabled also if a yearly subscription has been bought Resolves: http://gitlab.steamware.net/eqn/eqn.ios/-/issues/3
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,6 +47,12 @@ public struct VersioneProProducts {
|
||||
Subscription10kMonthly, Subscription10kYearly, Subscription10kYearlyDiscounted,
|
||||
Subscription100kMonthly, Subscription100kYearly, Subscription100kYearlyDiscounted
|
||||
]
|
||||
|
||||
static let identifierForProVersion: Set<ProductIdentifier> = [
|
||||
ProVersionFullPrice, ProVersionDiscounted,
|
||||
Subscription10kYearly, Subscription10kYearlyDiscounted,
|
||||
Subscription100kYearly, Subscription100kYearlyDiscounted
|
||||
]
|
||||
}
|
||||
|
||||
public static let store = IAPHelper(productIds: VersioneProProducts.Identifier.identifiers)
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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(), ^{
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user