Skip to content

Commit 2f01f3c

Browse files
committed
recover datafileListener
1 parent 754fad1 commit 2f01f3c

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

DemoSwiftApp/AppDelegate.swift

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4747
// - initialize immediately with the given JSON datafile or its cached copy
4848
// - no network delay, but the local copy is not guaranteed to be in sync with the server experiment settings
4949

50-
initializeOptimizelySDKAsynchronous()
50+
//// initializeOptimizelySDKAsynchronous()
51+
//// initializeOptimizelySDKSynchronous()
52+
initializeOptimizelySDKWithCustomization()
53+
5154
}
5255

5356
// MARK: - Initialization Examples
@@ -101,14 +104,32 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
101104

102105
// notification listeners
103106

104-
_ = optimizely?.notificationCenter.addDecisionNotificationListener(decisionListener: { (type, userId, attributes, decisionInfo) in
107+
_ = optimizely.notificationCenter.addDecisionNotificationListener(decisionListener: { (type, userId, attributes, decisionInfo) in
105108
print("Received decision notification: \(type) \(userId) \(String(describing: attributes)) \(decisionInfo)")
106109
})
107110

108-
_ = optimizely?.notificationCenter.addTrackNotificationListener(trackListener: { (eventKey, userId, attributes, eventTags, event) in
111+
_ = optimizely.notificationCenter.addTrackNotificationListener(trackListener: { (eventKey, userId, attributes, eventTags, event) in
109112
print("Received track notification: \(eventKey) \(userId) \(String(describing: attributes)) \(String(describing: eventTags)) \(event)")
110113
})
111114

115+
_ = optimizely.notificationCenter.addDatafileChangeNotificationListener(datafileListener: { (data) in
116+
DispatchQueue.main.async {
117+
#if os(iOS)
118+
let alert = UIAlertView(title: "Datafile change", message: "something changed.", delegate: nil, cancelButtonTitle: "cancel")
119+
alert.show()
120+
#else
121+
print("Datafile changed")
122+
#endif
123+
}
124+
125+
if let controller = self.window?.rootViewController as? VariationViewController {
126+
//controller.showCoupon = toggle == FeatureFlagToggle.on ? true : false;
127+
if let showCoupon = try? self.optimizely.isFeatureEnabled(featureKey: "show_coupon", userId: self.userId) {
128+
controller.showCoupon = showCoupon
129+
}
130+
}
131+
})
132+
112133
// initialize SDK
113134

114135
optimizely!.initializeSDK { result in

0 commit comments

Comments
 (0)