reteno-react-native-sdk 1.7.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -4
- package/android/build.gradle +1 -1
- package/android/src/main/AndroidManifest.xml +13 -3
- package/android/src/main/java/com/retenosdk/RetenoCustomReceiverInAppData.java +1 -11
- package/android/src/main/java/com/retenosdk/RetenoEcomEvent.java +20 -5
- package/android/src/main/java/com/retenosdk/RetenoMessagingService.java +5 -0
- package/android/src/main/java/com/retenosdk/RetenoSdkModule.java +439 -91
- package/ios/RetenoEcomEvent.swift +16 -25
- package/ios/RetenoSdk.m +20 -1
- package/ios/RetenoSdk.swift +286 -21
- package/lib/commonjs/index.js +127 -15
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +118 -15
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +102 -10
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +4 -7
- package/reteno-react-native-sdk.podspec +2 -17
- package/src/index.ts +186 -17
- package/android/src/main/java/com/retenosdk/RetenoReactNativeApplication.java +0 -7
- package/ios/RetenoSdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/RetenoSdk.xcodeproj/project.xcworkspace/xcuserdata/oleksandr.vasylkov.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/RetenoSdk.xcodeproj/xcuserdata/oleksandr.vasylkov.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
|
@@ -179,25 +179,21 @@ class RetenoEcomEvent: NSObject {
|
|
|
179
179
|
|
|
180
180
|
private static func buildOrderFromPayload(_ payload: [String: Any]?) -> Ecommerce.Order? {
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
case .delivered:
|
|
195
|
-
return Ecommerce.Order.Status(rawValue: "DELIVERED")!
|
|
196
|
-
case .cancelled:
|
|
197
|
-
return Ecommerce.Order.Status(rawValue: "CANCELLED")!
|
|
198
|
-
}
|
|
182
|
+
enum LocalStatus: Int {
|
|
183
|
+
case initialized = 0
|
|
184
|
+
case inprogress = 1
|
|
185
|
+
case delivered = 2
|
|
186
|
+
case cancelled = 3
|
|
187
|
+
|
|
188
|
+
var toOrderStatus: Ecommerce.Order.Status {
|
|
189
|
+
switch self {
|
|
190
|
+
case .initialized: return .INITIALIZED
|
|
191
|
+
case .inprogress: return .IN_PROGRESS
|
|
192
|
+
case .delivered: return .DELIVERED
|
|
193
|
+
case .cancelled: return .CANCELLED
|
|
199
194
|
}
|
|
200
195
|
}
|
|
196
|
+
}
|
|
201
197
|
|
|
202
198
|
|
|
203
199
|
guard let payload = payload else { return nil }
|
|
@@ -205,15 +201,10 @@ class RetenoEcomEvent: NSObject {
|
|
|
205
201
|
|
|
206
202
|
let externalCustomerId = payload["externalCustomerId"] as? String
|
|
207
203
|
guard let totalCost = payload["totalCost"] as? Float else { return nil }
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
guard let statusRaw = payload["status"] as? Int,
|
|
212
|
-
let localStatus = LocalStatus(rawValue: statusRaw) else { return nil }
|
|
213
|
-
|
|
214
|
-
let orderStatus = localStatus.toOrderStatus
|
|
204
|
+
guard let statusRaw = payload["status"] as? Int,
|
|
205
|
+
let localStatus = LocalStatus(rawValue: statusRaw) else { return nil }
|
|
206
|
+
let orderStatus = localStatus.toOrderStatus
|
|
215
207
|
|
|
216
|
-
|
|
217
208
|
let cartId = payload["cartId"] as? String
|
|
218
209
|
let email = payload["email"] as? String
|
|
219
210
|
let phone = payload["phone"] as? String
|
package/ios/RetenoSdk.m
CHANGED
|
@@ -28,6 +28,14 @@ RCT_EXTERN_METHOD(pauseInAppMessages:(BOOL)isPaused
|
|
|
28
28
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
29
29
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
30
30
|
|
|
31
|
+
RCT_EXTERN_METHOD(setInAppMessagesPauseBehaviour:(NSString*)behaviour
|
|
32
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
33
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
34
|
+
|
|
35
|
+
RCT_EXTERN_METHOD(setMultiAccountUserAttributes:(NSDictionary*)payload
|
|
36
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
37
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
38
|
+
|
|
31
39
|
RCT_EXTERN_METHOD(setInAppLifecycleCallback)
|
|
32
40
|
|
|
33
41
|
RCT_EXTERN_METHOD(getRecommendations:(NSDictionary*)payload
|
|
@@ -42,7 +50,14 @@ RCT_EXTERN_METHOD(getAppInboxMessages:(NSDictionary*)payload
|
|
|
42
50
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
43
51
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
44
52
|
|
|
45
|
-
RCT_EXTERN_METHOD(onUnreadMessagesCountChanged)
|
|
53
|
+
RCT_EXTERN_METHOD(onUnreadMessagesCountChanged:(RCTPromiseResolveBlock)resolve
|
|
54
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
55
|
+
|
|
56
|
+
RCT_EXTERN_METHOD(unsubscribeMessagesCountChanged:(RCTPromiseResolveBlock)resolve
|
|
57
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
58
|
+
|
|
59
|
+
RCT_EXTERN_METHOD(unsubscribeAllMessagesCountChanged:(RCTPromiseResolveBlock)resolve
|
|
60
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
46
61
|
|
|
47
62
|
RCT_EXTERN_METHOD(markAsOpened:(NSArray<NSString *> *)messageIds
|
|
48
63
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
@@ -59,6 +74,10 @@ RCT_EXTERN_METHOD(supportedEvents)
|
|
|
59
74
|
RCT_EXTERN_METHOD(initializeEventHandler:(RCTPromiseResolveBlock)resolve
|
|
60
75
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
61
76
|
|
|
77
|
+
RCT_EXTERN_METHOD(initialize:(NSDictionary *)payload
|
|
78
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
79
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
80
|
+
|
|
62
81
|
RCT_EXTERN_METHOD(setAutoOpenLinks:(BOOL)enabled
|
|
63
82
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
64
83
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
package/ios/RetenoSdk.swift
CHANGED
|
@@ -7,6 +7,15 @@ open class RetenoSdk: RCTEventEmitter {
|
|
|
7
7
|
|
|
8
8
|
private static let autoOpenLinksKey = "RetenoAutoOpenLinks"
|
|
9
9
|
|
|
10
|
+
private static var sdkInitialized = false
|
|
11
|
+
private static var fcmBridgeInstalled = false
|
|
12
|
+
private static var fcmTokenObserver: NSObjectProtocol?
|
|
13
|
+
|
|
14
|
+
/// Set to `true` once `delayedStart()` has registered Reteno as the notification-center delegate
|
|
15
|
+
/// from the AppDelegate. When set, JS `initialize()` finishes startup via `Reteno.delayedSetup(...)`
|
|
16
|
+
/// — which replays the push that cold-launched the app — instead of `Reteno.start(...)`.
|
|
17
|
+
private static var delayedStartCalled = false
|
|
18
|
+
|
|
10
19
|
private static var autoOpenLinks: Bool {
|
|
11
20
|
get {
|
|
12
21
|
if UserDefaults.standard.object(forKey: autoOpenLinksKey) == nil {
|
|
@@ -23,17 +32,41 @@ open class RetenoSdk: RCTEventEmitter {
|
|
|
23
32
|
super.init()
|
|
24
33
|
EventEmitter.sharedInstance.registerEventEmitter(externalEventEmitter: self)
|
|
25
34
|
|
|
26
|
-
// Listen for link events
|
|
35
|
+
// Listen for link events posted via NotificationCenter
|
|
27
36
|
NotificationCenter.default.addObserver(
|
|
28
37
|
self,
|
|
29
38
|
selector: #selector(handleLinkReceived(_:)),
|
|
30
39
|
name: NSNotification.Name("RetenoLinkReceived"),
|
|
31
40
|
object: nil
|
|
32
41
|
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// Registers Reteno as the `UNUserNotificationCenter` delegate early and starts collecting the
|
|
45
|
+
/// push response that cold-launched the app. Requires NO apiKey/config and is safe to call
|
|
46
|
+
/// repeatedly.
|
|
47
|
+
///
|
|
48
|
+
/// Call this from `application(_:didFinishLaunchingWithOptions:)`, BEFORE starting React Native,
|
|
49
|
+
/// to support push-triggered in-app messages on a cold start:
|
|
50
|
+
/// ```swift
|
|
51
|
+
/// func application(_ application: UIApplication, didFinishLaunchingWithOptions ...) -> Bool {
|
|
52
|
+
/// FirebaseApp.configure()
|
|
53
|
+
/// RetenoSdk.delayedStart()
|
|
54
|
+
/// ...
|
|
55
|
+
/// }
|
|
56
|
+
/// ```
|
|
57
|
+
/// iOS requires the notification-center delegate to be set before `didFinishLaunchingWithOptions`
|
|
58
|
+
/// returns; otherwise the response that cold-launched the app is never delivered and the linked
|
|
59
|
+
/// in-app never shows. The RN module's own `init()` runs too late (lazy instantiation), and
|
|
60
|
+
/// `Reteno.start()` registers the delegate only inside an async callback. `Reteno.delayedStart()`
|
|
61
|
+
/// sets it synchronously; JS `initialize()` then completes startup via `Reteno.delayedSetup(...)`,
|
|
62
|
+
/// which replays the collected push and presents its in-app.
|
|
63
|
+
@objc public static func delayedStart() {
|
|
64
|
+
guard !sdkInitialized, !delayedStartCalled else { return }
|
|
65
|
+
Reteno.delayedStart()
|
|
66
|
+
delayedStartCalled = true
|
|
67
|
+
}
|
|
33
68
|
|
|
34
|
-
|
|
35
|
-
// If AppDelegate already set a handler, this overrides it — which is fine,
|
|
36
|
-
// because cold start links were already handled by AppDelegate's handler
|
|
69
|
+
private func setupRetenoCallbacks() {
|
|
37
70
|
Reteno.addLinkHandler { linkInfo in
|
|
38
71
|
EventEmitter.sharedInstance.dispatch(
|
|
39
72
|
name: "reteno-in-app-custom-data-received",
|
|
@@ -72,9 +105,6 @@ open class RetenoSdk: RCTEventEmitter {
|
|
|
72
105
|
)
|
|
73
106
|
}
|
|
74
107
|
|
|
75
|
-
/// Base overide for RCTEventEmitter.
|
|
76
|
-
///
|
|
77
|
-
/// - Returns: all supported events
|
|
78
108
|
@objc open override func supportedEvents() -> [String] {
|
|
79
109
|
return EventEmitter.sharedInstance.allEvents;
|
|
80
110
|
}
|
|
@@ -85,6 +115,139 @@ open class RetenoSdk: RCTEventEmitter {
|
|
|
85
115
|
resolve(true)
|
|
86
116
|
}
|
|
87
117
|
|
|
118
|
+
@objc(initialize:withResolver:withRejecter:)
|
|
119
|
+
func initialize(payload: NSDictionary, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
120
|
+
if RetenoSdk.sdkInitialized {
|
|
121
|
+
resolve(true)
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let apiKey = (payload["apiKey"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
126
|
+
guard let apiKey = apiKey, !apiKey.isEmpty else {
|
|
127
|
+
reject("100", "Missing argument: apiKey", nil)
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let pauseInAppMessages = (payload["pauseInAppMessages"] as? Bool) ?? false
|
|
132
|
+
let isDebugMode = (payload["isDebugMode"] as? Bool) ?? false
|
|
133
|
+
|
|
134
|
+
let lifecycleOptionsInput = payload["lifecycleTrackingOptions"]
|
|
135
|
+
let lifecycleOptions = parseLifecycleTrackingOptions(lifecycleOptionsInput)
|
|
136
|
+
if lifecycleOptionsInput != nil && lifecycleOptions == nil {
|
|
137
|
+
reject(
|
|
138
|
+
"100",
|
|
139
|
+
"Invalid argument: lifecycleTrackingOptions. Expected 'ALL', 'NONE', or lifecycle options object.",
|
|
140
|
+
nil
|
|
141
|
+
)
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let lifecycleAppEnabled = lifecycleOptions?.appLifecycleEnabled ?? true
|
|
146
|
+
let lifecycleForegroundEnabled = lifecycleOptions?.foregroundLifecycleEnabled ?? false
|
|
147
|
+
let lifecyclePushEnabled = lifecycleOptions?.pushSubscriptionEnabled ?? true
|
|
148
|
+
let lifecycleSessionStartEnabled = lifecycleOptions?.sessionStartEventsEnabled ?? true
|
|
149
|
+
let lifecycleSessionEndEnabled = lifecycleOptions?.sessionEndEventsEnabled ?? false
|
|
150
|
+
|
|
151
|
+
let sessionDurationSeconds: TimeInterval = {
|
|
152
|
+
if let seconds = payload["sessionDurationSeconds"] as? Double, seconds > 0 {
|
|
153
|
+
return seconds
|
|
154
|
+
}
|
|
155
|
+
if let seconds = payload["sessionDurationSeconds"] as? Int, seconds > 0 {
|
|
156
|
+
return Double(seconds)
|
|
157
|
+
}
|
|
158
|
+
return RetenoSessionConfiguration.default.sessionDuration
|
|
159
|
+
}()
|
|
160
|
+
|
|
161
|
+
let deviceTokenMode: DeviceTokenHandlingMode = {
|
|
162
|
+
let raw = (payload["iosDeviceTokenHandlingMode"] as? String)?.lowercased()
|
|
163
|
+
return raw == "manual" ? .manual : .automatic
|
|
164
|
+
}()
|
|
165
|
+
|
|
166
|
+
let configuration = RetenoConfiguration(
|
|
167
|
+
isAutomaticScreenReportingEnabled: false,
|
|
168
|
+
isAutomaticAppLifecycleReportingEnabled: lifecycleAppEnabled,
|
|
169
|
+
isApplicationForegroundLifecycleReportingEnabled: lifecycleForegroundEnabled,
|
|
170
|
+
isAutomaticPushSubsriptionReportingEnabled: lifecyclePushEnabled,
|
|
171
|
+
sessionConfiguration: RetenoSessionConfiguration(
|
|
172
|
+
sessionDuration: sessionDurationSeconds,
|
|
173
|
+
isSessionStartReportingEnabled: lifecycleSessionStartEnabled,
|
|
174
|
+
isSessionEndReportingEnabled: lifecycleSessionEndEnabled
|
|
175
|
+
),
|
|
176
|
+
isPausedInAppMessages: pauseInAppMessages,
|
|
177
|
+
inAppMessagesPauseBehaviour: .postponeInApps,
|
|
178
|
+
isDebugMode: isDebugMode,
|
|
179
|
+
deviceTokenHandlingMode: deviceTokenMode
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
// When the AppDelegate called RetenoSdk.delayedStart(), finish the two-phase init so the
|
|
183
|
+
// push collected during cold start is replayed and its in-app is presented. Otherwise
|
|
184
|
+
// (no AppDelegate hook) start normally — everything works except cold-start push → in-app.
|
|
185
|
+
if RetenoSdk.delayedStartCalled {
|
|
186
|
+
Reteno.delayedSetup(apiKey: apiKey, configuration: configuration)
|
|
187
|
+
} else {
|
|
188
|
+
Reteno.start(apiKey: apiKey, configuration: configuration)
|
|
189
|
+
}
|
|
190
|
+
setupRetenoCallbacks()
|
|
191
|
+
if deviceTokenMode == .manual {
|
|
192
|
+
RetenoSdk.installFCMBridgeIfAvailable()
|
|
193
|
+
}
|
|
194
|
+
RetenoSdk.sdkInitialized = true
|
|
195
|
+
resolve(true)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private func parseLifecycleTrackingOptions(_ value: Any?) -> (
|
|
199
|
+
appLifecycleEnabled: Bool,
|
|
200
|
+
foregroundLifecycleEnabled: Bool,
|
|
201
|
+
pushSubscriptionEnabled: Bool,
|
|
202
|
+
sessionStartEventsEnabled: Bool,
|
|
203
|
+
sessionEndEventsEnabled: Bool
|
|
204
|
+
)? {
|
|
205
|
+
guard let value else { return nil }
|
|
206
|
+
|
|
207
|
+
if let optionString = value as? String {
|
|
208
|
+
let normalized = optionString.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
|
|
209
|
+
if normalized == "ALL" {
|
|
210
|
+
return (true, true, true, true, true)
|
|
211
|
+
}
|
|
212
|
+
if normalized == "NONE" {
|
|
213
|
+
return (false, false, false, false, false)
|
|
214
|
+
}
|
|
215
|
+
return nil
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
let payload: [String: Any]
|
|
219
|
+
if let dict = value as? [String: Any] {
|
|
220
|
+
payload = dict
|
|
221
|
+
} else if let dict = value as? NSDictionary, let casted = dict as? [String: Any] {
|
|
222
|
+
payload = casted
|
|
223
|
+
} else {
|
|
224
|
+
return nil
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
let appLifecycleEnabled = payload["appLifecycleEnabled"] as? Bool ?? true
|
|
228
|
+
let foregroundLifecycleEnabled = payload["foregroundLifecycleEnabled"] as? Bool ?? false
|
|
229
|
+
let pushSubscriptionEnabled = payload["pushSubscriptionEnabled"] as? Bool ?? true
|
|
230
|
+
let legacySessionEventsEnabled = payload["sessionEventsEnabled"] as? Bool ?? true
|
|
231
|
+
let sessionStartEventsEnabled = payload["sessionStartEventsEnabled"] as? Bool ?? legacySessionEventsEnabled
|
|
232
|
+
|
|
233
|
+
let sessionEndEventsEnabled: Bool
|
|
234
|
+
if let explicit = payload["sessionEndEventsEnabled"] as? Bool {
|
|
235
|
+
sessionEndEventsEnabled = explicit
|
|
236
|
+
} else if payload["sessionEventsEnabled"] != nil {
|
|
237
|
+
sessionEndEventsEnabled = legacySessionEventsEnabled
|
|
238
|
+
} else {
|
|
239
|
+
sessionEndEventsEnabled = false
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
appLifecycleEnabled,
|
|
244
|
+
foregroundLifecycleEnabled,
|
|
245
|
+
pushSubscriptionEnabled,
|
|
246
|
+
sessionStartEventsEnabled,
|
|
247
|
+
sessionEndEventsEnabled
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
88
251
|
@objc(setAutoOpenLinks:withResolver:withRejecter:)
|
|
89
252
|
func setAutoOpenLinks(enabled: Bool, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
90
253
|
RetenoSdk.autoOpenLinks = enabled
|
|
@@ -98,13 +261,14 @@ open class RetenoSdk: RCTEventEmitter {
|
|
|
98
261
|
|
|
99
262
|
@objc(setDeviceToken:withResolver:withRejecter:)
|
|
100
263
|
func setDeviceToken(deviceToken: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
101
|
-
Reteno.userNotificationService.processRemoteNotificationsToken(deviceToken)
|
|
264
|
+
Reteno.userNotificationService.processRemoteNotificationsToken(deviceToken)
|
|
265
|
+
resolve(true)
|
|
102
266
|
}
|
|
103
267
|
|
|
104
268
|
@objc(setUserAttributes:withResolver:withRejecter:)
|
|
105
269
|
func setUserAttributes(payload: NSDictionary, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
106
270
|
let externalUserId = payload["externalUserId"] as? String;
|
|
107
|
-
|
|
271
|
+
|
|
108
272
|
do {
|
|
109
273
|
let requestPayload = try RetenoUserAttributes.buildSetUserAttributesPayload(payload: payload);
|
|
110
274
|
Reteno.updateUserAttributes(
|
|
@@ -115,12 +279,37 @@ open class RetenoSdk: RCTEventEmitter {
|
|
|
115
279
|
groupNamesExclude: requestPayload.groupNamesExclude
|
|
116
280
|
);
|
|
117
281
|
let res:[String:Bool] = ["success":true];
|
|
118
|
-
|
|
282
|
+
|
|
119
283
|
resolve(res);
|
|
120
284
|
} catch {
|
|
121
285
|
reject("100", "Reteno iOS SDK Error", error);
|
|
122
286
|
}
|
|
123
287
|
}
|
|
288
|
+
|
|
289
|
+
@objc(setMultiAccountUserAttributes:withResolver:withRejecter:)
|
|
290
|
+
func setMultiAccountUserAttributes(payload: NSDictionary, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
291
|
+
let externalUserId = payload["externalUserId"] as? String
|
|
292
|
+
|
|
293
|
+
guard let externalUserId = externalUserId, !externalUserId.isEmpty else {
|
|
294
|
+
reject("100", "Missing argument: externalUserId", nil)
|
|
295
|
+
return
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
do {
|
|
299
|
+
let requestPayload = try RetenoUserAttributes.buildSetUserAttributesPayload(payload: payload)
|
|
300
|
+
Reteno.updateMultiAccountUserAttributes(
|
|
301
|
+
externalUserId: externalUserId,
|
|
302
|
+
userAttributes: requestPayload.userAttributes,
|
|
303
|
+
subscriptionKeys: requestPayload.subscriptionKeys,
|
|
304
|
+
groupNamesInclude: requestPayload.groupNamesInclude,
|
|
305
|
+
groupNamesExclude: requestPayload.groupNamesExclude,
|
|
306
|
+
accountSuffix: externalUserId
|
|
307
|
+
)
|
|
308
|
+
resolve(["success": true])
|
|
309
|
+
} catch {
|
|
310
|
+
reject("100", "Reteno iOS SDK Error", error)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
124
313
|
|
|
125
314
|
@objc(getInitialNotification:withRejecter:)
|
|
126
315
|
func getInitialNotification(_ resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
@@ -157,9 +346,40 @@ open class RetenoSdk: RCTEventEmitter {
|
|
|
157
346
|
|
|
158
347
|
@objc(registerForRemoteNotifications)
|
|
159
348
|
func registerForRemoteNotifications() -> Void {
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
349
|
+
// Shows the native iOS notification permission prompt (.sound, .alert, .badge).
|
|
350
|
+
Reteno.userNotificationService.registerForRemoteNotifications(with: [.sound, .alert, .badge], application: UIApplication.shared)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Installs an FCM token bridge using the ObjC runtime — no Firebase import required.
|
|
354
|
+
// Subscribes to FIRMessagingRegistrationTokenRefreshedNotification and reads
|
|
355
|
+
// FIRMessaging.messaging().FCMToken via KVC. Does NOT replace Messaging.delegate
|
|
356
|
+
// so @react-native-firebase/messaging internals are not affected.
|
|
357
|
+
private static func installFCMBridgeIfAvailable() {
|
|
358
|
+
guard !fcmBridgeInstalled else { return }
|
|
359
|
+
guard NSClassFromString("FIRMessaging") != nil else {
|
|
360
|
+
NSLog("[Reteno] iosDeviceTokenHandlingMode='manual': FIRMessaging not found at runtime. Provide the push token via setDeviceToken().")
|
|
361
|
+
return
|
|
362
|
+
}
|
|
363
|
+
fcmBridgeInstalled = true
|
|
364
|
+
fcmTokenObserver = NotificationCenter.default.addObserver(
|
|
365
|
+
forName: Notification.Name("com.firebase.messaging.notif.fcm-token-refreshed"),
|
|
366
|
+
object: nil,
|
|
367
|
+
queue: .main
|
|
368
|
+
) { _ in
|
|
369
|
+
RetenoSdk.forwardFCMTokenToReteno()
|
|
370
|
+
}
|
|
371
|
+
// Forward any already-cached token on subsequent launches.
|
|
372
|
+
forwardFCMTokenToReteno()
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
private static func forwardFCMTokenToReteno() {
|
|
376
|
+
guard
|
|
377
|
+
let fmClass = NSClassFromString("FIRMessaging") as? NSObject.Type,
|
|
378
|
+
let messaging = fmClass.perform(NSSelectorFromString("messaging"))?.takeUnretainedValue() as? NSObject,
|
|
379
|
+
let token = messaging.value(forKey: "FCMToken") as? String,
|
|
380
|
+
!token.isEmpty
|
|
381
|
+
else { return }
|
|
382
|
+
Reteno.userNotificationService.processRemoteNotificationsToken(token)
|
|
163
383
|
}
|
|
164
384
|
|
|
165
385
|
@objc(setAnonymousUserAttributes:withResolver:withRejecter:)
|
|
@@ -176,8 +396,23 @@ open class RetenoSdk: RCTEventEmitter {
|
|
|
176
396
|
|
|
177
397
|
@objc(pauseInAppMessages:withResolver:withRejecter:)
|
|
178
398
|
func pauseInAppMessages(isPaused: Bool, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
|
179
|
-
Reteno.pauseInAppMessages(isPaused: isPaused)
|
|
180
|
-
resolve(true)
|
|
399
|
+
Reteno.pauseInAppMessages(isPaused: isPaused)
|
|
400
|
+
resolve(true)
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
@objc(setInAppMessagesPauseBehaviour:withResolver:withRejecter:)
|
|
404
|
+
func setInAppMessagesPauseBehaviour(behaviour: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
405
|
+
let normalized = behaviour.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
|
|
406
|
+
switch normalized {
|
|
407
|
+
case "SKIP_IN_APPS":
|
|
408
|
+
Reteno.setInAppMessagesPauseBehaviour(pauseBehaviour: .skipInApps)
|
|
409
|
+
resolve(true)
|
|
410
|
+
case "POSTPONE_IN_APPS":
|
|
411
|
+
Reteno.setInAppMessagesPauseBehaviour(pauseBehaviour: .postponeInApps)
|
|
412
|
+
resolve(true)
|
|
413
|
+
default:
|
|
414
|
+
reject("100", "Invalid argument: behaviour must be 'SKIP_IN_APPS' or 'POSTPONE_IN_APPS'", nil)
|
|
415
|
+
}
|
|
181
416
|
}
|
|
182
417
|
|
|
183
418
|
@objc(setInAppLifecycleCallback)
|
|
@@ -189,15 +424,32 @@ open class RetenoSdk: RCTEventEmitter {
|
|
|
189
424
|
case .inAppIsDisplayed:
|
|
190
425
|
EventEmitter.sharedInstance.dispatch(name: "reteno-on-in-app-display", body: nil)
|
|
191
426
|
case .inAppShouldBeClosed(let action):
|
|
192
|
-
EventEmitter.sharedInstance.dispatch(name: "reteno-before-in-app-close", body: [
|
|
427
|
+
EventEmitter.sharedInstance.dispatch(name: "reteno-before-in-app-close", body: [
|
|
428
|
+
"closeAction": RetenoSdk.closeActionName(action),
|
|
429
|
+
"isCloseButtonClicked": action.isCloseButtonClicked,
|
|
430
|
+
"isButtonClicked": action.isButtonClicked,
|
|
431
|
+
"isOpenUrlClicked": action.isOpenUrlClicked
|
|
432
|
+
])
|
|
193
433
|
case .inAppIsClosed(let action):
|
|
194
|
-
EventEmitter.sharedInstance.dispatch(name: "reteno-after-in-app-close", body: [
|
|
434
|
+
EventEmitter.sharedInstance.dispatch(name: "reteno-after-in-app-close", body: [
|
|
435
|
+
"closeAction": RetenoSdk.closeActionName(action),
|
|
436
|
+
"isCloseButtonClicked": action.isCloseButtonClicked,
|
|
437
|
+
"isButtonClicked": action.isButtonClicked,
|
|
438
|
+
"isOpenUrlClicked": action.isOpenUrlClicked
|
|
439
|
+
])
|
|
195
440
|
case .inAppReceivedError(let error):
|
|
196
|
-
EventEmitter.sharedInstance.dispatch(name: "reteno-on-in-app-error", body: ["
|
|
441
|
+
EventEmitter.sharedInstance.dispatch(name: "reteno-on-in-app-error", body: ["errorMessage": error])
|
|
197
442
|
}
|
|
198
443
|
}
|
|
199
444
|
}
|
|
200
445
|
|
|
446
|
+
private static func closeActionName(_ action: InAppMessageAction) -> String {
|
|
447
|
+
if action.isCloseButtonClicked { return "CLOSE_BUTTON" }
|
|
448
|
+
if action.isButtonClicked { return "BUTTON" }
|
|
449
|
+
if action.isOpenUrlClicked { return "OPEN_URL" }
|
|
450
|
+
return "UNKNOWN"
|
|
451
|
+
}
|
|
452
|
+
|
|
201
453
|
@objc(getRecommendations:withResolver:withRejecter:)
|
|
202
454
|
func getRecommendations(payload: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
203
455
|
guard let recomVariantId = payload["recomVariantId"] as? String,
|
|
@@ -313,11 +565,24 @@ open class RetenoSdk: RCTEventEmitter {
|
|
|
313
565
|
}
|
|
314
566
|
}
|
|
315
567
|
|
|
316
|
-
@objc(onUnreadMessagesCountChanged)
|
|
317
|
-
func onUnreadMessagesCountChanged() {
|
|
568
|
+
@objc(onUnreadMessagesCountChanged:withRejecter:)
|
|
569
|
+
func onUnreadMessagesCountChanged(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
318
570
|
Reteno.inbox().onUnreadMessagesCountChanged = { count in
|
|
319
571
|
EventEmitter.sharedInstance.dispatch(name: "reteno-unread-messages-count", body: ["count": count])
|
|
320
572
|
}
|
|
573
|
+
resolve(nil)
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
@objc(unsubscribeMessagesCountChanged:withRejecter:)
|
|
577
|
+
func unsubscribeMessagesCountChanged(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
578
|
+
Reteno.inbox().onUnreadMessagesCountChanged = nil
|
|
579
|
+
resolve(nil)
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
@objc(unsubscribeAllMessagesCountChanged:withRejecter:)
|
|
583
|
+
func unsubscribeAllMessagesCountChanged(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
584
|
+
Reteno.inbox().onUnreadMessagesCountChanged = nil
|
|
585
|
+
resolve(nil)
|
|
321
586
|
}
|
|
322
587
|
|
|
323
588
|
@objc(markAsOpened:withResolver:withRejecter:)
|
|
@@ -500,5 +765,5 @@ open class RetenoSdk: RCTEventEmitter {
|
|
|
500
765
|
} catch {
|
|
501
766
|
reject("Reteno iOS SDK Error", error.localizedDescription, error)
|
|
502
767
|
}
|
|
503
|
-
}
|
|
768
|
+
}
|
|
504
769
|
}
|