Verify feature/provider eligibility

Limit hosts to 2.
This commit is contained in:
Davide De Rosa 2019-10-28 10:14:03 +01:00
parent e99cc3669d
commit 6e46757d99
7 changed files with 56 additions and 2 deletions

View File

@ -97,8 +97,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
guard let root = window?.rootViewController else {
fatalError("No window.rootViewController?")
}
let topmost = root.presentedViewController ?? root
if TransientStore.shared.service.hasReachedMaximumNumberOfHosts {
guard ProductManager.shared.isEligible(forFeature: .unlimitedHosts) else {
topmost.presentPurchaseScreen(forProduct: .unlimitedHosts)
return false
}
}
return tryParseURL(url, passphrase: nil, target: topmost)
}

View File

@ -107,3 +107,9 @@ extension Infrastructure.Name {
return product
}
}
extension AppConstants {
struct InApp {
public static let limitedNumberOfHosts = 2
}
}

View File

@ -159,6 +159,13 @@ class ProductManager: NSObject {
}
}
extension ConnectionService {
var hasReachedMaximumNumberOfHosts: Bool {
let numberOfHosts = ids(forContext: .host).count
return numberOfHosts >= AppConstants.InApp.limitedNumberOfHosts
}
}
extension ProductManager: SKPaymentTransactionObserver {
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
reloadReceipt()

View File

@ -71,7 +71,7 @@ class ImportedHostsViewController: UITableViewController {
// MARK: Actions
@IBAction private func openConfigurationFile() {
let picker = UIDocumentPickerViewController(documentTypes: ["public.content", "public.data"], in: .import)
let picker = UIDocumentPickerViewController(documentTypes: AppConstants.URLs.filetypes, in: .import)
picker.allowsMultipleSelection = false
picker.delegate = self
present(picker, animated: true, completion: nil)

View File

@ -204,10 +204,20 @@ class OrganizerViewController: UITableViewController, StrongTableHost {
}
private func addNewHost() {
if TransientStore.shared.service.hasReachedMaximumNumberOfHosts {
guard ProductManager.shared.isEligible(forFeature: .unlimitedHosts) else {
presentPurchaseScreen(forProduct: .unlimitedHosts)
return
}
}
perform(segue: StoryboardSegue.Organizer.showImportedHostsSegueIdentifier)
}
private func addShortcuts() {
guard ProductManager.shared.isEligible(forFeature: .siriShortcuts) else {
presentPurchaseScreen(forProduct: .siriShortcuts)
return
}
perform(segue: StoryboardSegue.Organizer.siriShortcutsSegueIdentifier)
}

View File

@ -38,6 +38,11 @@ class WizardProviderViewController: UITableViewController {
}
private func next(withName name: Infrastructure.Name) {
guard ProductManager.shared.isEligible(forProvider: name) else {
presentPurchaseScreen(forProduct: name.product)
return
}
let profile = ProviderConnectionProfile(name: name)
createdProfile = profile

View File

@ -347,6 +347,14 @@ class ServiceViewController: UIViewController, StrongTableHost {
}
private func trustMobileNetwork(cell: ToggleTableViewCell) {
guard ProductManager.shared.isEligible(forFeature: .trustedNetworks) else {
delay {
cell.setOn(false, animated: true)
}
presentPurchaseScreen(forProduct: .trustedNetworks)
return
}
if #available(iOS 12, *) {
IntentDispatcher.donateTrustCellularNetwork()
IntentDispatcher.donateUntrustCellularNetwork()
@ -356,6 +364,11 @@ class ServiceViewController: UIViewController, StrongTableHost {
}
private func trustCurrentWiFi() {
guard ProductManager.shared.isEligible(forFeature: .trustedNetworks) else {
presentPurchaseScreen(forProduct: .trustedNetworks)
return
}
if #available(iOS 13, *) {
let auth = CLLocationManager.authorizationStatus()
switch auth {
@ -400,6 +413,14 @@ class ServiceViewController: UIViewController, StrongTableHost {
}
private func toggleTrustWiFi(cell: ToggleTableViewCell, at row: Int) {
guard ProductManager.shared.isEligible(forFeature: .trustedNetworks) else {
delay {
cell.setOn(false, animated: true)
}
presentPurchaseScreen(forProduct: .trustedNetworks)
return
}
if cell.isOn {
trustedNetworks.enableWifi(at: row)
} else {