From 5e9c1019908ca3d6f197be601b9b2d5985bbc0cd Mon Sep 17 00:00:00 2001 From: Andrea Busi Date: Thu, 30 Jul 2020 21:07:16 +0200 Subject: [PATCH] fix: General improvements on purchase restore --- .../InApp/PurchaseProVersionViewController.swift | 6 +++++- .../InApp/SubscriptionsViewController.swift | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Sources/Earthquake Network/Controllers/InApp/PurchaseProVersionViewController.swift b/Sources/Earthquake Network/Controllers/InApp/PurchaseProVersionViewController.swift index db6f119..8cb63dc 100644 --- a/Sources/Earthquake Network/Controllers/InApp/PurchaseProVersionViewController.swift +++ b/Sources/Earthquake Network/Controllers/InApp/PurchaseProVersionViewController.swift @@ -149,8 +149,12 @@ class PurchaseProVersionViewController: UIViewController { let alert = UIAlertController(title: NSLocalizedString("purchase_pro_restore_alert_title", comment: ""), message: NSLocalizedString("purchase_pro_restore_alert_message", comment: ""), preferredStyle: .alert) - alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) + alert.addAction(UIAlertAction(title: "OK", style: .default) { [weak self] _ in + self?.navigationController?.popViewController(animated: true) + }) present(alert, animated: true) + } else { + navigationController?.popViewController(animated: true) } } diff --git a/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift b/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift index 9c2e36c..324155c 100644 --- a/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift +++ b/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift @@ -40,6 +40,8 @@ class SubscriptionsViewController: UITableViewController { private var availability: EQNPurchaseAvailability? /// Tells if products are loading private var isLoading = false + /// Tells if a restore is in progress + private var isRestorePurchase = false // MARK: - View Lifecycle @@ -155,7 +157,8 @@ class SubscriptionsViewController: UITableViewController { // MARK: - Actions @objc func restoreTapped(_ sender: AnyObject) { - VersioneProProducts.store.restorePurchases() + isRestorePurchase = true + VersioneProProducts.store.restorePurchases() } // MARK: - Notifications @@ -165,6 +168,15 @@ class SubscriptionsViewController: UITableViewController { } @objc func handlePurchaseNotification(_ notification: Notification) { + if isRestorePurchase { + isRestorePurchase = false + + let alert = UIAlertController(title: NSLocalizedString("purchase_pro_restore_alert_title", comment: ""), + message: NSLocalizedString("purchase_pro_restore_alert_message", comment: ""), preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) + present(alert, animated: true, completion: nil) + } + VersioneProProducts.store.loadPurchase() loadData() }