summaryrefslogtreecommitdiffhomepage
path: root/ios
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-04-02 13:20:14 +0200
committerAndrej Mihajlov <and@mullvad.net>2020-04-02 13:20:14 +0200
commite3ee60352bd8915126deeb411b93fc931361b4df (patch)
tree98a2ec4ba1b510e3944a2fbff664b9806426668f /ios
parent7ca44f805a4ed113663fcddd8a2d30c6be475f24 (diff)
downloadmullvadvpn-e3ee60352bd8915126deeb411b93fc931361b4df.tar.xz
mullvadvpn-e3ee60352bd8915126deeb411b93fc931361b4df.zip
Handle a failure to load the IAPs from AppStore
Diffstat (limited to 'ios')
-rw-r--r--ios/MullvadVPN/AccountViewController.swift18
1 files changed, 15 insertions, 3 deletions
diff --git a/ios/MullvadVPN/AccountViewController.swift b/ios/MullvadVPN/AccountViewController.swift
index cb216947d5..48a1f7d72e 100644
--- a/ios/MullvadVPN/AccountViewController.swift
+++ b/ios/MullvadVPN/AccountViewController.swift
@@ -30,7 +30,8 @@ class AccountViewController: UIViewController {
private lazy var purchaseButtonInteractionRestriction =
UserInterfaceInteractionRestriction(scheduler: DispatchQueue.main) {
[weak self] (enableUserInteraction, _) in
- self?.purchaseButton.isEnabled = enableUserInteraction
+ // Make sure to disable the button if the product is not loaded
+ self?.purchaseButton.isEnabled = enableUserInteraction && self?.product != nil
}
private lazy var viewControllerInteractionRestriction =
@@ -97,9 +98,11 @@ class AccountViewController: UIViewController {
.receive(on: DispatchQueue.main)
.restrictUserInterfaceInteraction(with: self.purchaseButtonInteractionRestriction, animated: true)
.sink(receiveCompletion: { [weak self] (completion) in
- if case .finished = completion {
- self?.purchaseButton.isLoading = false
+ if case .failure(let error) = completion {
+ self?.didFailLoadingProducts(with: error)
}
+
+ self?.purchaseButton.isLoading = false
}, receiveValue: { [weak self] (response) in
if let product = response.products.first {
self?.setProduct(product, animated: true)
@@ -122,6 +125,15 @@ class AccountViewController: UIViewController {
purchaseButton.setTitle(title, for: .normal)
}
+ private func didFailLoadingProducts(with error: Error) {
+ let title = NSLocalizedString(
+ "Cannot connect to AppStore",
+ comment: "The buy button title displayed when unable to load the price of subscription"
+ )
+
+ purchaseButton.setTitle(title, for: .normal)
+ }
+
private func setEnableUserInteraction(_ enableUserInteraction: Bool, animated: Bool) {
// Disable all buttons
[restoreButton, logoutButton].forEach { (button) in