-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathPaywallService.swift
77 lines (58 loc) · 2.18 KB
/
PaywallService.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// PaywallService.swift
// LockdowniOS
//
// Created by Aliaksandr Dvoineu on 4.05.23.
// Copyright © 2023 Confirmed Inc. All rights reserved.
//
import CocoaLumberjackSwift
import StoreKit
import UIKit
protocol PaywallService: AnyObject {
var context: PaywallContext { get set }
func showPaywall(on vc: UIViewController, forceSpecialOffer: Bool)
func showRedemptionSheet()
}
final class BasePaywallService: PaywallService {
var context: PaywallContext = .normal
var countdownDisplayService: CountdownDisplayService = BaseCountdownDisplayService.shared
static let shared = BasePaywallService()
private init() {}
func showPaywall(on vc: UIViewController, forceSpecialOffer: Bool = false) {
defer {
UserDefaults.lastPaywallDisplayDate = Date()
}
// let paywall = TablePaywallViewController()
// paywall.modalPresentationStyle = .formSheet
// if let delegate = vc as? PaywallViewControllerCloseDelegate {
// paywall.delegate = delegate
// }
//
// vc.definesPresentationContext = true
// vc.present(paywall, animated: true) {
// vc.definesPresentationContext = false
// }
}
func showRedemptionSheet() {
guard #available(iOS 14.0, *) else { return }
SKPaymentQueue.default().presentCodeRedemptionSheet()
context = .redeemOfferCode
DDLogInfo("Showing redemption sheet, changing context to \(context)")
}
}
extension BasePaywallService: CountdownDisplayDelegate {
func didFinishCountdown() {
countdownDisplayService.pauseUpdating()
context = .normal
}
}
extension BasePaywallService: Keychainable {}
enum PaywallContext {
/// The context that shows a normal paywall without LTO discounts.
case normal
/// The context that shows an LTO paywall with a holiday discount
/// Only after an ordinary paywall has been closed.
case followUpLimitedTimeOffer
/// When user is in the process of code redemption after calling presentCodeRedemptionSheet() method.
case redeemOfferCode
}