diff --git a/Sources/Earthquake Network/AppDelegate.m b/Sources/Earthquake Network/AppDelegate.m index 47a6b3e..94b2daa 100644 --- a/Sources/Earthquake Network/AppDelegate.m +++ b/Sources/Earthquake Network/AppDelegate.m @@ -78,9 +78,9 @@ [[EQNManager defaultManager] avviaManager]; [[EQNAccelerometroManager sharedInstance] startUpdatingLocationBackground]; - NSUInteger counter = [[NSUserDefaults standardUserDefaults] integerForKey:CONTEGGIO_APERTURE_PER_SCONTO]; + NSUInteger counter = [[NSUserDefaults standardUserDefaults] integerForKey:EQNUserDefaultProDiscountOpenCounter]; counter += 1; - [[NSUserDefaults standardUserDefaults] setInteger:counter forKey:CONTEGGIO_APERTURE_PER_SCONTO]; + [[NSUserDefaults standardUserDefaults] setInteger:counter forKey:EQNUserDefaultProDiscountOpenCounter]; } diff --git a/Sources/Earthquake Network/Controllers/EQNBaseViewController.h b/Sources/Earthquake Network/Controllers/EQNBaseViewController.h index 29ef4c1..f3ed402 100644 --- a/Sources/Earthquake Network/Controllers/EQNBaseViewController.h +++ b/Sources/Earthquake Network/Controllers/EQNBaseViewController.h @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)refreshUI; -/// Handle `IAPHelperPurchaseNotification` notification +/// Handle `EQNNotificationDidCompleteInAppPurchase` notification /// @param notification Notification fired - (void)didReceiveInAppNotification:(NSNotification *)notification; diff --git a/Sources/Earthquake Network/Controllers/EQNBaseViewController.m b/Sources/Earthquake Network/Controllers/EQNBaseViewController.m index f9769ad..96b2a0a 100644 --- a/Sources/Earthquake Network/Controllers/EQNBaseViewController.m +++ b/Sources/Earthquake Network/Controllers/EQNBaseViewController.m @@ -27,7 +27,7 @@ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveInAppNotification:) - name:IAPHelperPurchaseNotification object:nil]; + name:EQNNotificationDidCompleteInAppPurchase object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveDownloadCompleteNotification:) diff --git a/Sources/Earthquake Network/Controllers/InApp/PurchaseProVersionViewController.swift b/Sources/Earthquake Network/Controllers/InApp/PurchaseProVersionViewController.swift index e7d8bba..c2b3852 100644 --- a/Sources/Earthquake Network/Controllers/InApp/PurchaseProVersionViewController.swift +++ b/Sources/Earthquake Network/Controllers/InApp/PurchaseProVersionViewController.swift @@ -35,7 +35,7 @@ class PurchaseProVersionViewController: UIViewController { super.viewDidLoad() NotificationCenter.default.addObserver(self, selector: #selector(handlePurchaseNotification(_:)), - name: .IAPHelperPurchaseNotification, + name: .EQNNotificationDidCompleteInAppPurchase, object: nil) configureUI() diff --git a/Sources/Earthquake Network/Controllers/InApp/SubscriptionDetailViewController.swift b/Sources/Earthquake Network/Controllers/InApp/SubscriptionDetailViewController.swift index c1596c2..c4c2d9a 100644 --- a/Sources/Earthquake Network/Controllers/InApp/SubscriptionDetailViewController.swift +++ b/Sources/Earthquake Network/Controllers/InApp/SubscriptionDetailViewController.swift @@ -36,7 +36,7 @@ class SubscriptionDetailViewController: UIViewController { super.viewDidLoad() NotificationCenter.default.addObserver(self, selector: #selector(handlePurchaseNotification(_:)), - name: .IAPHelperPurchaseNotification, + name: .EQNNotificationDidCompleteInAppPurchase, object: nil) updateUI() diff --git a/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift b/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift index d7662c2..56259e0 100644 --- a/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift +++ b/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift @@ -73,11 +73,11 @@ class SubscriptionsViewController: UITableViewController { private func addObservers() { NotificationCenter.default.addObserver(self, selector: #selector(handlePurchaseNotification(_:)), - name: .IAPHelperPurchaseNotification, + name: .EQNNotificationDidCompleteInAppPurchase, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(fail(_:)), - name: .IAPHelperPurchaseNotificationFail, + name: .EQNNotificationDidCompleteInAppPurchaseFail, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleNoTransactionsNotification(_:)), diff --git a/Sources/Earthquake Network/Costanti.h b/Sources/Earthquake Network/Costanti.h index b9cb307..e669e45 100644 --- a/Sources/Earthquake Network/Costanti.h +++ b/Sources/Earthquake Network/Costanti.h @@ -67,6 +67,10 @@ static NSString * const EQNUserDefaultKeySesmicInformations = @"EQNetwork.Seismi static NSString * const EQNUserDefaultKeyOneShotShowCountry = @"EQNetwork.OneShot.CountrySelection"; static NSString * const EQNUserDefaultLastLocation = @"EQNLast_Location"; static NSString * const EQNUserDefaultSeismicNetworkCards = @"EQNData.RetiSismiche"; +/// Numero di aperture dell'app per sbloccare la versione Pro scontata +static NSString * const EQNUserDefaultProDiscountOpenCounter = @"CONTEGGIO_APERTURE_PER_SCONTO"; +/// Prezzo scontato per la versione pro scaduto +static NSString * const EQNUserDefaultProDiscountExpired = @"PREZZO_SCONTATO_SCADUTO"; #pragma mark - NSNotification @@ -74,6 +78,8 @@ static NSString * const EQNUserDefaultSeismicNetworkCards = @"EQNData.RetiSismic static NSString * const EQNNotificationDidChangeAuthorizationStatus = @"EQNNotificationDidChangeAuthorizationStatus"; /// Notifica di completamento download dei dati static NSString * const EQNNotificationDidDownloadData = @"EQNNotificationDidDownloadData"; +/// Notifica di acquisto in-app effettuato +static NSString * const EQNNotificationDidCompleteInAppPurchase = @"EQNNotificationDidCompleteInAppPurchase"; #pragma mark - Other constants @@ -236,11 +242,6 @@ typedef enum : NSInteger { #define EQN_ADMOB_ANNUNCIO_IDA @"ca-app-pub-0053870219990922/3394298808" #define EQN_ADMOB_ANNUNCIO_IDA_TEST @"ca-app-pub-3940256099942544/2934735716" -// ACQUISTI IN APP -#define CONTEGGIO_APERTURE_PER_SCONTO @"CONTEGGIO_APERTURE_PER_SCONTO" -#define PREZZO_SCONTATO_SCADUTO @"PREZZO_SCONTATO_SCADUTO" -#define IAPHelperPurchaseNotification @"IAPHelperPurchaseNotification" - // FILTRO ENTI #define EQN_MAGNITUDO_MINIMA @"EQN_MAGNITUDO_MINIMA" #define EQN_DISTANZA_MASSIMA @"EQN_DISTANZA_MASSIMA" diff --git a/Sources/Earthquake Network/Models/EQNPurchaseUtility.swift b/Sources/Earthquake Network/Models/EQNPurchaseUtility.swift index 6058463..5a2d6e7 100644 --- a/Sources/Earthquake Network/Models/EQNPurchaseUtility.swift +++ b/Sources/Earthquake Network/Models/EQNPurchaseUtility.swift @@ -20,13 +20,13 @@ public class EQNPurchaseUtility: NSObject { /// If zero, no discounted price is available /// - Parameter completion: Completion static func offerTimeRemaining(completion: @escaping (_ timeRemaining: Int) -> Void) { - let appOpenCounter = UserDefaults.standard.integer(forKey:CONTEGGIO_APERTURE_PER_SCONTO) + let appOpenCounter = UserDefaults.standard.integer(forKey:EQNUserDefaultProDiscountOpenCounter) if appOpenCounter < Self.AppOpenCountForDiscount { completion(0) return } - let discountExpired = UserDefaults.standard.bool(forKey: PREZZO_SCONTATO_SCADUTO) + let discountExpired = UserDefaults.standard.bool(forKey: EQNUserDefaultProDiscountExpired) if discountExpired { completion(0) return @@ -34,7 +34,7 @@ public class EQNPurchaseUtility: NSObject { EQNUser.default().downloadOfferTimeRemaining { (timeOffer) in if timeOffer == 0 { - UserDefaults.standard.set(true, forKey: PREZZO_SCONTATO_SCADUTO) + UserDefaults.standard.set(true, forKey: EQNUserDefaultProDiscountExpired) } let timeInHours = timeOffer / 60 @@ -90,13 +90,13 @@ public class EQNPurchaseUtility: NSObject { VersioneProProducts.Identifier.identifiers.forEach { (identifier) in UserDefaults.standard.removeObject(forKey: identifier) } - NotificationCenter.default.post(name: .IAPHelperPurchaseNotification, object: nil) + NotificationCenter.default.post(name: .EQNNotificationDidCompleteInAppPurchase, object: nil) } /// Use to simulate the purchase of the Pro version @objc public static func simulateProPurchase(identifier: String) { // store and notify UserDefaults.standard.set(true, forKey: identifier) - NotificationCenter.default.post(name: .IAPHelperPurchaseNotification, object: identifier) + NotificationCenter.default.post(name: .EQNNotificationDidCompleteInAppPurchase, object: identifier) } } diff --git a/Sources/Earthquake Network/Models/IAPHelper.swift b/Sources/Earthquake Network/Models/IAPHelper.swift index e7da81b..12b3f23 100644 --- a/Sources/Earthquake Network/Models/IAPHelper.swift +++ b/Sources/Earthquake Network/Models/IAPHelper.swift @@ -32,8 +32,8 @@ public typealias ProductIdentifier = String public typealias ProductsRequestCompletionHandler = (_ success: Bool, _ products: [SKProduct]?) -> Void extension Notification.Name { - static let IAPHelperPurchaseNotification = Notification.Name("IAPHelperPurchaseNotification") - static let IAPHelperPurchaseNotificationFail = Notification.Name("IAPHelperPurchaseNotificationFail") + static let EQNNotificationDidCompleteInAppPurchase = Notification.Name("EQNNotificationDidCompleteInAppPurchase") + static let EQNNotificationDidCompleteInAppPurchaseFail = Notification.Name("EQNNotificationDidCompleteInAppPurchaseFail") /// No available transactions to restore static let IAPHelperPurchaseNoTransactions = Notification.Name("IAPHelperPurchaseNoTransactions") @@ -146,7 +146,7 @@ extension IAPHelper: SKPaymentTransactionObserver { public func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) { print("[IAPHelper] Restore transaction failed (error : \(error.localizedDescription))") - NotificationCenter.default.post(name: .IAPHelperPurchaseNotificationFail, object: nil) + NotificationCenter.default.post(name: .EQNNotificationDidCompleteInAppPurchaseFail, object: nil) } public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { @@ -201,7 +201,7 @@ extension IAPHelper: SKPaymentTransactionObserver { print("[IAPHelper] Handle failed transaction error: \(localizedDescription)") } - NotificationCenter.default.post(name: .IAPHelperPurchaseNotificationFail, object: nil) + NotificationCenter.default.post(name: .EQNNotificationDidCompleteInAppPurchaseFail, object: nil) SKPaymentQueue.default().finishTransaction(transaction) } @@ -210,7 +210,7 @@ extension IAPHelper: SKPaymentTransactionObserver { purchasedProductIdentifiers.insert(identifier) UserDefaults.standard.set(true, forKey: identifier) - NotificationCenter.default.post(name: .IAPHelperPurchaseNotification, object: identifier) + NotificationCenter.default.post(name: .EQNNotificationDidCompleteInAppPurchase, object: identifier) } private func serverPurchaseRegistration(for productId: String, transactionId: String?) {