diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2020-04-02 13:20:14 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2020-04-02 13:20:14 +0200 |
| commit | e3ee60352bd8915126deeb411b93fc931361b4df (patch) | |
| tree | 98a2ec4ba1b510e3944a2fbff664b9806426668f | |
| parent | 7ca44f805a4ed113663fcddd8a2d30c6be475f24 (diff) | |
| download | mullvadvpn-e3ee60352bd8915126deeb411b93fc931361b4df.tar.xz mullvadvpn-e3ee60352bd8915126deeb411b93fc931361b4df.zip | |
Handle a failure to load the IAPs from AppStore
| -rw-r--r-- | ios/MullvadVPN/AccountViewController.swift | 18 |
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 |
