-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathWelcomeViewController.swift
74 lines (62 loc) · 2.1 KB
/
WelcomeViewController.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
//
// WelcomeViewController.swift
// SuperwallUIKitExample
//
// Created by Yusuf Tör on 05/04/2022.
//
import UIKit
import SuperwallKit
import RevenueCat
final class WelcomeViewController: UIViewController {
@IBOutlet private var textFieldBackgroundView: UIView!
@IBOutlet private var textField: UITextField!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = true
}
override func viewDidLoad() {
super.viewDidLoad()
if Superwall.shared.isLoggedIn {
next()
}
textFieldBackgroundView.layer.cornerRadius = textFieldBackgroundView.frame.height / 2
textField.delegate = self
UINavigationBar.appearance().titleTextAttributes = [
.foregroundColor: UIColor.white,
.font: UIFont.rubikBold(.five)
]
navigationController?.interactivePopGestureRecognizer?.isEnabled = false
}
@IBAction private func logIn() {
if let username = textField.text {
if username.isEmpty {
let alert = UIAlertController(title: "Username Left Blank", message: "How would you like to continue?", preferredStyle: .alert)
let useAnonymous = UIAlertAction(title: "Anonymous Account", style: .default) { [weak self] _ in
self?.next()
}
let useUsername = UIAlertAction(title: "Pick Username", style: .default)
alert.addAction(useAnonymous)
alert.addAction(useUsername)
present(alert, animated: true)
return
}
Superwall.shared.setUserAttributes(["firstName": username])
Superwall.shared.identify(userId: "abc_\(username)")
Task {
try? await Purchases.shared.logIn("abc_\(username)")
}
next()
}
}
private func next() {
let trackEventViewController = HomeViewController.fromStoryboard()
navigationController?.pushViewController(trackEventViewController, animated: true)
}
}
// MARK: - UITextFieldDelegate
extension WelcomeViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
_ = textField.resignFirstResponder()
return true
}
}