@@ -49,7 +49,110 @@ open class OptimizelyManager: NSObject {
49
49
return HandlerRegistryService . shared. injectNotificationCenter ( sdkKey: self . sdkKey) !
50
50
}
51
51
}
52
-
52
+
53
+ @available ( swift, obsoleted: 1.0 )
54
+ @objc ( notificationCenter) public var objc_notificationCenter : Objc_OPTNotificationCenter {
55
+ class ObjcCenter : Objc_OPTNotificationCenter {
56
+ var notifications : OPTNotificationCenter
57
+
58
+ init ( notificationCenter: OPTNotificationCenter ) {
59
+ notifications = notificationCenter
60
+ }
61
+
62
+ func addActivateNotificationListener( activateListener: @escaping ( [ String : Any ] , String , [ String : Any ] ? , [ String : Any ] , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
63
+
64
+ let num = notifications. addActivateNotificationListener { ( experiment, userId, attributes, variation, event) in
65
+
66
+ let attrs = attributes? . mapValues ( { ( val) -> Any in
67
+ if let val = val {
68
+ return val
69
+ }
70
+ else {
71
+ return NSNull ( )
72
+ }
73
+ } )
74
+ activateListener ( experiment, userId, attrs, variation, event)
75
+ }
76
+
77
+ if let num = num {
78
+ return NSNumber ( value: num)
79
+ }
80
+
81
+ return nil
82
+ }
83
+
84
+ func addTrackNotificationListener( trackListener: @escaping ( String , String , [ String : Any ] ? , Dictionary < String , Any > ? , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
85
+ let num = notifications. addTrackNotificationListener { ( eventKey, userId, attributes, eventTags, event) in
86
+
87
+ let attrs = attributes? . mapValues ( { ( val) -> Any in
88
+ if let val = val {
89
+ return val
90
+ }
91
+ else {
92
+ return NSNull ( )
93
+ }
94
+ } )
95
+
96
+ trackListener ( eventKey, userId, attrs, eventTags, event)
97
+
98
+ }
99
+
100
+ if let num = num {
101
+ return NSNumber ( value: num)
102
+ }
103
+
104
+ return nil
105
+ }
106
+
107
+ func addDecisionNotificationListener( decisionListener: @escaping ( String , String , [ String : Any ] ? , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
108
+
109
+ let num = notifications. addDecisionNotificationListener { ( type, userId, attributes, decisionInfo) in
110
+ let attrs = attributes? . mapValues ( { ( val) -> Any in
111
+ if let val = val {
112
+ return val
113
+ }
114
+ else {
115
+ return NSNull ( )
116
+ }
117
+ } )
118
+ decisionListener ( type, userId, attrs, decisionInfo)
119
+ }
120
+ if let num = num {
121
+ return NSNumber ( value: num)
122
+ }
123
+
124
+ return nil
125
+ }
126
+
127
+ func addDatafileChangeNotificationListener( datafileListener: @escaping ( Data ) -> Void ) -> NSNumber ? {
128
+ let num = notifications. addDatafileChangeNotificationListener { ( data) in
129
+ datafileListener ( data)
130
+ }
131
+ if let num = num {
132
+ return NSNumber ( value: num)
133
+ }
134
+
135
+ return nil
136
+ }
137
+
138
+ func removeNotificationListener( notificationId: Int ) {
139
+ notifications. removeNotificationListener ( notificationId: notificationId)
140
+ }
141
+
142
+ func clearNotificationListeners( type: NotificationType ) {
143
+ notifications. clearNotificationListeners ( type: type)
144
+ }
145
+
146
+ func clearAllNotificationListeners( ) {
147
+ notifications. clearAllNotificationListeners ( )
148
+ }
149
+
150
+
151
+ }
152
+
153
+ return ObjcCenter ( notificationCenter: self . notificationCenter)
154
+ }
155
+
53
156
private let reInitLock = Dispatch . DispatchSemaphore ( value: 1 )
54
157
55
158
// MARK: - Public interfaces
0 commit comments