Make feature purchase optional
This commit is contained in:
parent
9d0bddfc3c
commit
47da4ba5af
|
@ -230,7 +230,7 @@ extension WizardProviderViewController: AccountViewControllerDelegate {
|
|||
// MARK: -
|
||||
|
||||
extension WizardProviderViewController: PurchaseViewControllerDelegate {
|
||||
func purchaseController(_ purchaseController: PurchaseViewController, didPurchase product: Product) {
|
||||
func purchaseController(_ purchaseController: PurchaseViewController, didPurchase product: Product?) {
|
||||
guard let metadata = selectedMetadata else {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -32,13 +32,13 @@ import Convenience
|
|||
private let log = SwiftyBeaver.self
|
||||
|
||||
protocol PurchaseViewControllerDelegate: class {
|
||||
func purchaseController(_ purchaseController: PurchaseViewController, didPurchase product: Product)
|
||||
func purchaseController(_ purchaseController: PurchaseViewController, didPurchase product: Product?)
|
||||
}
|
||||
|
||||
class PurchaseViewController: UITableViewController, StrongTableHost {
|
||||
private var isLoading = true
|
||||
|
||||
var feature: Product!
|
||||
var feature: Product?
|
||||
|
||||
weak var delegate: PurchaseViewControllerDelegate?
|
||||
|
||||
|
@ -71,7 +71,7 @@ class PurchaseViewController: UITableViewController, StrongTableHost {
|
|||
self.skFullVersion = skFullVersion
|
||||
rows.append(.fullVersion)
|
||||
}
|
||||
if let skFeature = pm.product(withIdentifier: feature) {
|
||||
if let feature = feature, let skFeature = pm.product(withIdentifier: feature) {
|
||||
self.skFeature = skFeature
|
||||
rows.append(.feature)
|
||||
}
|
||||
|
@ -96,10 +96,6 @@ class PurchaseViewController: UITableViewController, StrongTableHost {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
guard let _ = feature else {
|
||||
fatalError("No feature set for purchase")
|
||||
}
|
||||
|
||||
title = L10n.Core.Purchase.title
|
||||
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(close))
|
||||
|
||||
|
@ -168,7 +164,7 @@ class PurchaseViewController: UITableViewController, StrongTableHost {
|
|||
guard let weakSelf = self else {
|
||||
return
|
||||
}
|
||||
let product = weakSelf.feature.matchesStoreKitProduct(skProduct) ? weakSelf.feature! : .fullVersion
|
||||
let product = Product(rawValue: skProduct.productIdentifier)
|
||||
weakSelf.delegate?.purchaseController(weakSelf, didPurchase: product)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import Convenience
|
|||
private let log = SwiftyBeaver.self
|
||||
|
||||
protocol PurchaseViewControllerDelegate: class {
|
||||
func purchaseController(_ purchaseController: PurchaseViewController, didPurchase product: Product)
|
||||
func purchaseController(_ purchaseController: PurchaseViewController, didPurchase product: Product?)
|
||||
}
|
||||
|
||||
class PurchaseViewController: NSViewController {
|
||||
|
@ -52,7 +52,7 @@ class PurchaseViewController: NSViewController {
|
|||
|
||||
@IBOutlet private weak var buttonRestore: NSButton!
|
||||
|
||||
var feature: Product!
|
||||
var feature: Product?
|
||||
|
||||
weak var delegate: PurchaseViewControllerDelegate?
|
||||
|
||||
|
@ -79,7 +79,7 @@ class PurchaseViewController: NSViewController {
|
|||
self.skFullVersion = skFullVersion
|
||||
rows.append(.fullVersion)
|
||||
}
|
||||
if let skFeature = pm.product(withIdentifier: feature) {
|
||||
if let feature = feature, let skFeature = pm.product(withIdentifier: feature) {
|
||||
self.skFeature = skFeature
|
||||
rows.append(.feature)
|
||||
}
|
||||
|
@ -108,10 +108,6 @@ class PurchaseViewController: NSViewController {
|
|||
buttonPurchase.title = L10n.Core.Purchase.title
|
||||
buttonRestore.title = L10n.Core.Purchase.Cells.Restore.title
|
||||
|
||||
guard let _ = feature else {
|
||||
fatalError("No feature set for purchase")
|
||||
}
|
||||
|
||||
tableView.usesAutomaticRowHeights = true
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
@ -197,7 +193,7 @@ class PurchaseViewController: NSViewController {
|
|||
guard let weakSelf = self else {
|
||||
return
|
||||
}
|
||||
let product = weakSelf.feature.matchesStoreKitProduct(skProduct) ? weakSelf.feature! : .fullVersion
|
||||
let product = Product(rawValue: skProduct.productIdentifier)
|
||||
weakSelf.delegate?.purchaseController(weakSelf, didPurchase: product)
|
||||
|
||||
self?.dismiss(nil)
|
||||
|
|
Loading…
Reference in New Issue