-
Notifications
You must be signed in to change notification settings - Fork 29
/
AppDelegate.swift
83 lines (63 loc) · 2.41 KB
/
AppDelegate.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
import BrazeKit
import BrazeLocation
import BrazeUI
import Flutter
import SDWebImage
import UIKit
import braze_plugin
let brazeApiKey = "9292484d-3b10-4e67-971d-ff0c0d518e21"
let brazeEndpoint = "sondheim.appboy.com"
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, BrazeInAppMessageUIDelegate {
// The subscription needs to be retained to be active
var contentCardsSubscription: Braze.Cancellable?
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
// - Setup Braze
let configuration = Braze.Configuration(apiKey: brazeApiKey, endpoint: brazeEndpoint)
configuration.sessionTimeout = 1
configuration.triggerMinimumTimeInterval = 0
configuration.location.automaticLocationCollection = true
configuration.location.brazeLocationProvider = BrazeLocationProvider()
configuration.logger.level = .debug
let braze = BrazePlugin.initBraze(configuration)
// - GIF support
GIFViewProvider.shared = .sdWebImage
// - InAppMessage UI
let inAppMessageUI = BrazeInAppMessageUI()
inAppMessageUI.delegate = self
braze.inAppMessagePresenter = inAppMessageUI
contentCardsSubscription = braze.contentCards.subscribeToUpdates { contentCards in
print("=> [Content Card Subscription] Received cards:", contentCards)
// Pass each content card model to the Dart layer.
BrazePlugin.processContentCards(contentCards)
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
// MARK: BrazeInAppMessageUIDelegate
func inAppMessage(
_ ui: BrazeInAppMessageUI,
willPresent message: Braze.InAppMessage,
view: InAppMessageView
) {
print("=> [In-app Message] Received message from Braze:", message)
// Pass in-app message data to the Dart layer.
BrazePlugin.processInAppMessage(message)
}
}
// MARK: GIF support
extension GIFViewProvider {
public static let sdWebImage = Self(
view: { SDAnimatedImageView(image: image(for: $0)) },
updateView: { ($0 as? SDAnimatedImageView)?.image = image(for: $1) }
)
private static func image(for url: URL?) -> UIImage? {
guard let url = url else { return nil }
return url.pathExtension == "gif"
? SDAnimatedImage(contentsOfFile: url.path)
: UIImage(contentsOfFile: url.path)
}
}