-
Notifications
You must be signed in to change notification settings - Fork 15
/
ContentCardSettingsViewController.swift
74 lines (64 loc) · 2.88 KB
/
ContentCardSettingsViewController.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
import UIKit
class ContentCardSettingsViewController: UIViewController {
// MARK: - Outlets
@IBOutlet private weak var segmentedControl: UISegmentedControl!
// MARK: - Actions
@IBAction func apiTriggeredCampaignButtonPressed(_ sender: Any) {
guard let userId = BrazeManager.shared.userId, !userId.isEmpty else {
return presentAlert(title: "NO-EXTERNAL-ID", message: "Sign in to launch API Triggered Campaign")
}
handleApiTriggeredCampaignKey(userId)
}
@IBAction func resetHomeScreenButtonPressed(_ sender: Any) {
NotificationCenter.default.post(name: .defaultAppExperience, object: nil)
presentAlert(title: "Reset Home Screen", message: nil)
}
@IBAction func eventRemovalCampaignButtonPressed(_ sender: Any) {
let eventTitle = "Group Event Removal Campaign Pressed"
BrazeManager.shared.logCustomEvent(eventTitle)
presentAlert(title: eventTitle, message: nil)
}
@IBAction func segmentChanged(_ sender: UISegmentedControl) {
RemoteStorage().store(sender.selectedSegmentIndex, forKey: .messageCenterStyle)
}
@IBAction func messageCenterCampaignButtonPressed(_ sender: UIButton) {
handleMessageCenterCampaignButtonPressed(with: sender.titleLabel?.text)
}
}
// MARK: - View Lifecycle
extension ContentCardSettingsViewController {
override func viewDidLoad() {
super.viewDidLoad()
configureMessageCenterSegmentedControl()
}
}
// MARK: - Private
private extension ContentCardSettingsViewController {
func configureMessageCenterSegmentedControl() {
if let value = RemoteStorage().retrieve(forKey: .messageCenterStyle) as? Int {
segmentedControl.selectedSegmentIndex = value
}
}
func handleMessageCenterCampaignButtonPressed(with title: String?) {
guard let title = title else { return }
let eventTitle = "\(title) Pressed"
BrazeManager.shared.logCustomEvent(eventTitle)
presentAlert(title: eventTitle, message: nil)
}
func handleApiTriggeredCampaignKey(_ userId: String) {
let tileCampaignId = "YOUR-CAMPAIGN-ID"
let tileCampaignAPIKey = "YOUR-CAMPAIGN-API-KEY"
let tileTriggerProperties = ["tile_title": "Currents 101 Live Training",
"tile_detail": "Introduction to Currents covers the basics of data exports from Braze.",
"tile_image": "https://cc.sj-cdn.net/instructor/2mwq54fjyfsk3-braze/courses/2bffl8kjacmwy/promo-image.1585681509.png",
"tile_price": "250.00",
"tile_tags": "Currents",
"tile_deeplink": ""]
APIRequestBuilder.make(campaignId: tileCampaignId, campaignAPIKey: tileCampaignAPIKey, userId: userId, tileTriggerProperties) { [weak self] alertTitle in
guard let self = self else { return }
DispatchQueue.main.async {
self.presentAlert(title: alertTitle, message: nil)
}
}
}
}