Restore provider flow after purchase

This commit is contained in:
Davide De Rosa 2019-12-04 14:16:50 +01:00
parent 99445dfe3c
commit 23f1cfdad3
5 changed files with 39 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}
}

View File

@ -35,6 +35,8 @@ class WizardProviderViewController: UITableViewController, StrongTableHost {
private var createdProfile: ProviderConnectionProfile?
private var selectedMetadata: Infrastructure.Metadata?
// MARK: StrongTableHost
let model = StrongTableModel<SectionType, RowType>()
@ -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)
}
}

View File

@ -30,11 +30,17 @@ 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?
private var skFullVersion: 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)
}
}
}