diff --git a/CHANGELOG.md b/CHANGELOG.md index 0518f50f..41c53412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - "Trusted networks" settings are now saved per profile. [#114](https://github.com/passepartoutvpn/passepartout-ios/issues/114) - Require explicit `--ca` and `--cipher` in .ovpn configuration file. +- Restore provider flow after purchase. ### Fixed diff --git a/Passepartout-iOS/Global/Macros.swift b/Passepartout-iOS/Global/Macros.swift index 556944f7..68f2dad7 100644 --- a/Passepartout-iOS/Global/Macros.swift +++ b/Passepartout-iOS/Global/Macros.swift @@ -63,10 +63,11 @@ extension UIColor { } extension UIViewController { - func presentPurchaseScreen(forProduct product: Product) { + func presentPurchaseScreen(forProduct product: Product, delegate: PurchaseViewControllerDelegate? = nil) { let nav = StoryboardScene.Purchase.initialScene.instantiate() let vc = nav.topViewController as? PurchaseViewController vc?.feature = product + vc?.delegate = delegate // enforce pre iOS 13 behavior nav.modalPresentationStyle = .fullScreen diff --git a/Passepartout-iOS/Global/Product.swift b/Passepartout-iOS/Global/Product.swift index 9c209ffc..1bd4691f 100644 --- a/Passepartout-iOS/Global/Product.swift +++ b/Passepartout-iOS/Global/Product.swift @@ -24,6 +24,7 @@ // import Foundation +import StoreKit import PassepartoutCore struct Product: RawRepresentable, Equatable, Hashable { @@ -139,3 +140,9 @@ extension Infrastructure.Metadata { return Product(providerId: inApp ?? description) } } + +extension Product { + func matchesStoreKitProduct(_ skProduct: SKProduct) -> Bool { + return skProduct.productIdentifier == rawValue + } +} diff --git a/Passepartout-iOS/Scenes/Organizer/WizardProviderViewController.swift b/Passepartout-iOS/Scenes/Organizer/WizardProviderViewController.swift index a9f029fc..a32e58c7 100644 --- a/Passepartout-iOS/Scenes/Organizer/WizardProviderViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/WizardProviderViewController.swift @@ -35,6 +35,8 @@ class WizardProviderViewController: UITableViewController, StrongTableHost { private var createdProfile: ProviderConnectionProfile? + private var selectedMetadata: Infrastructure.Metadata? + // MARK: StrongTableHost let model = StrongTableModel() @@ -59,6 +61,8 @@ class WizardProviderViewController: UITableViewController, StrongTableHost { } private func tryNext(withMetadata metadata: Infrastructure.Metadata) { + selectedMetadata = metadata + guard ProductManager.shared.isEligible(forProvider: metadata.name) else { presentPurchaseScreen(forProduct: metadata.product, delegate: self) return @@ -214,3 +218,14 @@ extension WizardProviderViewController: AccountViewControllerDelegate { finish(withCredentials: vc.credentials) } } + +// MARK: - + +extension WizardProviderViewController: PurchaseViewControllerDelegate { + func purchaseController(_ purchaseController: PurchaseViewController, didPurchase product: Product) { + guard let metadata = selectedMetadata else { + return + } + tryNext(withMetadata: metadata) + } +} diff --git a/Passepartout-iOS/Scenes/Purchase/PurchaseViewController.swift b/Passepartout-iOS/Scenes/Purchase/PurchaseViewController.swift index 5903ae22..bb6607ea 100644 --- a/Passepartout-iOS/Scenes/Purchase/PurchaseViewController.swift +++ b/Passepartout-iOS/Scenes/Purchase/PurchaseViewController.swift @@ -30,10 +30,16 @@ import Convenience private let log = SwiftyBeaver.self +protocol PurchaseViewControllerDelegate: class { + func purchaseController(_ purchaseController: PurchaseViewController, didPurchase product: Product) +} + class PurchaseViewController: UITableViewController, StrongTableHost { private var isLoading = true var feature: Product! + + weak var delegate: PurchaseViewControllerDelegate? private var skFeature: SKProduct? @@ -135,7 +141,14 @@ class PurchaseViewController: UITableViewController, StrongTableHost { } return } - self?.dismiss(animated: true, completion: nil) + + self?.dismiss(animated: true) { + guard let weakSelf = self else { + return + } + let product = weakSelf.feature.matchesStoreKitProduct(skProduct) ? weakSelf.feature! : .fullVersion + weakSelf.delegate?.purchaseController(weakSelf, didPurchase: product) + } } }