-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathHomeView.swift
104 lines (94 loc) · 3.27 KB
/
HomeView.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// TrackEventView.swift
// SuperwallSwiftUIExample
//
// Created by Yusuf Tör on 11/03/2022.
//
import SwiftUI
import SuperwallKit
struct HomeView: View {
@Binding var isLoggedIn: Bool
@State private var launchFeature = false
init(isLoggedIn: Binding<Bool>) {
_isLoggedIn = isLoggedIn
UINavigationBar.appearance().titleTextAttributes = [
.foregroundColor: UIColor.white,
.font: UIFont.rubikBold(.five)
]
}
var firstName: String {
Superwall.shared.userAttributes["firstName"] as? String ?? ""
}
var body: some View {
VStack(spacing: 48) {
ScrollView {
InfoView(
text: "The Launch Feature button below registers an event \"campaign_trigger\".\n\nThis event has been added to a campaign on the Superwall dashboard.\n\nWhen this event is registered, the rules in the campaign are evaluated.\n\nThe rules match and cause a paywall to show."
)
Divider()
.background(Color.primaryTeal)
.padding()
SuperwallSubscriptionStatusView()
}
VStack(spacing: 25) {
BrandedButton(title: "Launch Feature") {
let handler = PaywallPresentationHandler()
handler.onDismiss { paywallInfo in
print("The paywall dismissed. PaywallInfo:", paywallInfo)
}
handler.onPresent { paywallInfo in
print("The paywall presented. PaywallInfo:", paywallInfo)
}
handler.onError { error in
print("The paywall presentation failed with error \(error)")
}
handler.onSkip { reason in
switch reason {
case .userIsSubscribed:
print("Paywall not shown because user is subscribed.")
case .holdout(let experiment):
print("Paywall not shown because user is in a holdout group in Experiment: \(experiment.id)")
case .noRuleMatch:
print("Paywall not shown because user doesn't match any rules.")
case .eventNotFound:
print("Paywall not shown because this event isn't part of a campaign.")
}
}
Superwall.shared.register(event: "campaign_trigger", handler: handler) {
// code in here can be remotely configured to execute. Either
// (1) always after presentation or
// (2) only if the user pays
// code is always executed if no paywall is configured to show
launchFeature = true
}
}
BrandedButton(title: "Log Out") {
Superwall.shared.reset()
isLoggedIn = false
}
}
.padding()
}
.frame(maxHeight: .infinity)
.foregroundColor(.white)
.background(Color.neutral)
.navigationBarTitleDisplayMode(.inline)
.navigationBarBackButtonHidden()
.navigationTitle("Hello \(firstName)")
.alert(
"Launched Feature",
isPresented: $launchFeature,
actions: {
Button("OK", role: .cancel) {}
},
message: {
Text("Wrap your awesome features in register calls like this to remotely paywall your app. You can remotely decide whether these are paid features.")
}
)
}
}
struct TrackEventView_Previews: PreviewProvider {
static var previews: some View {
HomeView(isLoggedIn: .constant(false))
}
}