summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-04-02 14:17:46 +0200
committerAndrej Mihajlov <and@mullvad.net>2020-04-02 14:17:46 +0200
commit4881fbab863b5530116f885e8296c8a4dd5a9e6e (patch)
tree60f7226e29a0e2d5fb3d56be4138ff5118fe06c4
parente3ee60352bd8915126deeb411b93fc931361b4df (diff)
downloadmullvadvpn-4881fbab863b5530116f885e8296c8a4dd5a9e6e.tar.xz
mullvadvpn-4881fbab863b5530116f885e8296c8a4dd5a9e6e.zip
Disable purchases and avoid fetching IAPs when device cannot make payments
-rw-r--r--ios/MullvadVPN/AccountViewController.swift18
-rw-r--r--ios/MullvadVPN/AppStorePaymentManager.swift5
2 files changed, 21 insertions, 2 deletions
diff --git a/ios/MullvadVPN/AccountViewController.swift b/ios/MullvadVPN/AccountViewController.swift
index 48a1f7d72e..d49e156532 100644
--- a/ios/MullvadVPN/AccountViewController.swift
+++ b/ios/MullvadVPN/AccountViewController.swift
@@ -31,7 +31,9 @@ class AccountViewController: UIViewController {
UserInterfaceInteractionRestriction(scheduler: DispatchQueue.main) {
[weak self] (enableUserInteraction, _) in
// Make sure to disable the button if the product is not loaded
- self?.purchaseButton.isEnabled = enableUserInteraction && self?.product != nil
+ self?.purchaseButton.isEnabled = enableUserInteraction &&
+ self?.product != nil &&
+ AppStorePaymentManager.canMakePayments
}
private lazy var viewControllerInteractionRestriction =
@@ -73,7 +75,12 @@ class AccountViewController: UIViewController {
updateAccountExpiry(expiryDate: expiryDate)
}
- requestStoreProducts()
+ // Make sure to disable IAPs when payments are restricted
+ if AppStorePaymentManager.canMakePayments {
+ requestStoreProducts()
+ } else {
+ setPaymentsRestricted()
+ }
}
// MARK: - Private methods
@@ -134,6 +141,13 @@ class AccountViewController: UIViewController {
purchaseButton.setTitle(title, for: .normal)
}
+ private func setPaymentsRestricted() {
+ let title = NSLocalizedString("Payments restricted", comment: "")
+
+ purchaseButton.setTitle(title, for: .normal)
+ purchaseButton.isEnabled = false
+ }
+
private func setEnableUserInteraction(_ enableUserInteraction: Bool, animated: Bool) {
// Disable all buttons
[restoreButton, logoutButton].forEach { (button) in
diff --git a/ios/MullvadVPN/AppStorePaymentManager.swift b/ios/MullvadVPN/AppStorePaymentManager.swift
index 7addb58d52..04a4928fe4 100644
--- a/ios/MullvadVPN/AppStorePaymentManager.swift
+++ b/ios/MullvadVPN/AppStorePaymentManager.swift
@@ -124,6 +124,11 @@ class AppStorePaymentManager {
/// A private hash map that maps each payment to account token
private var paymentToAccountToken = [SKPayment: String]()
+ /// Returns true if the device is able to make payments
+ class var canMakePayments: Bool {
+ return SKPaymentQueue.canMakePayments()
+ }
+
init(queue: SKPaymentQueue) {
self.queue = queue
}