@allboatsrise/expo-marketingcloudsdk 47.0.0-android.24 → 47.0.0-android.26
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.
|
@@ -2,7 +2,10 @@ import ExpoModulesCore
|
|
|
2
2
|
import SFMCSDK
|
|
3
3
|
import MarketingCloudSDK
|
|
4
4
|
|
|
5
|
-
public class ExpoMarketingCloudSdkModule: Module {
|
|
5
|
+
public class ExpoMarketingCloudSdkModule: Module, ExpoMarketingCloudSdkLoggerDelegate {
|
|
6
|
+
private var refreshInboxPromise: Promise?
|
|
7
|
+
private var logger: ExpoMarketingCloudSdkLogger?
|
|
8
|
+
|
|
6
9
|
// Each module class must implement the definition function. The definition consists of components
|
|
7
10
|
// that describes the module's functionality and behavior.
|
|
8
11
|
// See https://docs.expo.dev/modules/module-api for more details about available components.
|
|
@@ -14,6 +17,24 @@ public class ExpoMarketingCloudSdkModule: Module {
|
|
|
14
17
|
|
|
15
18
|
// Defines event names that the module can send to JavaScript.
|
|
16
19
|
Events("onLog", "onInboxResponse")
|
|
20
|
+
|
|
21
|
+
OnStartObserving {
|
|
22
|
+
if (logger == nil) {
|
|
23
|
+
self.logger = ExpoMarketingCloudSdkLogger()
|
|
24
|
+
self.logger!.delegate = self
|
|
25
|
+
SFMCSdk.setLogger(logLevel: .debug, logOutputter: self.logger!)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
NotificationCenter.default.addObserver(self, selector: #selector(self.inboxMessagesNewInboxMessagesListener), name: NSNotification.Name.SFMCInboxMessagesNewInboxMessages, object: nil)
|
|
29
|
+
|
|
30
|
+
NotificationCenter.default.addObserver(self, selector: #selector(self.inboxMessagesRefreshCompleteListener), name: NSNotification.Name.SFMCInboxMessagesRefreshComplete, object: nil)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
OnStopObserving {
|
|
34
|
+
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.SFMCInboxMessagesNewInboxMessages, object: nil)
|
|
35
|
+
|
|
36
|
+
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.SFMCInboxMessagesRefreshComplete, object: nil)
|
|
37
|
+
}
|
|
17
38
|
|
|
18
39
|
AsyncFunction("isPushEnabled") { (promise: Promise) in
|
|
19
40
|
promise.resolve(SFMCSdk.mp.pushEnabled())
|
|
@@ -32,14 +53,14 @@ public class ExpoMarketingCloudSdkModule: Module {
|
|
|
32
53
|
AsyncFunction("getSystemToken") { (promise: Promise) in
|
|
33
54
|
promise.resolve(SFMCSdk.mp.deviceToken())
|
|
34
55
|
}
|
|
35
|
-
|
|
56
|
+
|
|
36
57
|
AsyncFunction("setSystemToken") { (token: String, promise: Promise) in
|
|
37
58
|
do {
|
|
38
59
|
let token = try ExpoMarketingCloudSdkDeviceToken.init(hexString: token)
|
|
39
60
|
SFMCSdk.mp.setDeviceToken(token.data)
|
|
40
61
|
promise.resolve(SFMCSdk.mp.deviceToken())
|
|
41
62
|
} catch {
|
|
42
|
-
|
|
63
|
+
promise.reject("invalid-hex-token", "Failed to convert token to data type")
|
|
43
64
|
}
|
|
44
65
|
}
|
|
45
66
|
|
|
@@ -87,7 +108,7 @@ public class ExpoMarketingCloudSdkModule: Module {
|
|
|
87
108
|
}
|
|
88
109
|
|
|
89
110
|
AsyncFunction("track") { (name: String, attributes: Dictionary<String, Any>, promise: Promise) in
|
|
90
|
-
let event = CustomEvent(name: name, attributes: attributes)
|
|
111
|
+
let event = CustomEvent(name: name, attributes: attributes)!
|
|
91
112
|
SFMCSdk.track(event: event)
|
|
92
113
|
promise.resolve(true)
|
|
93
114
|
}
|
|
@@ -136,11 +157,44 @@ public class ExpoMarketingCloudSdkModule: Module {
|
|
|
136
157
|
}
|
|
137
158
|
|
|
138
159
|
AsyncFunction("refreshInbox") { (promise: Promise) in
|
|
139
|
-
|
|
160
|
+
let successful = SFMCSdk.mp.refreshMessages()
|
|
161
|
+
if (successful == false) {
|
|
162
|
+
promise.resolve(false)
|
|
163
|
+
} else {
|
|
164
|
+
// resolve previous promise if one exists
|
|
165
|
+
self.refreshInboxPromise?.resolve(false)
|
|
166
|
+
|
|
167
|
+
// queue latest promise
|
|
168
|
+
self.refreshInboxPromise = promise
|
|
169
|
+
}
|
|
140
170
|
}
|
|
141
171
|
|
|
142
172
|
AsyncFunction("setMessageRead") { (messageId: String, promise: Promise) in
|
|
143
173
|
promise.resolve(SFMCSdk.mp.markMessageWithIdRead(messageId: messageId))
|
|
144
174
|
}
|
|
145
175
|
}
|
|
176
|
+
|
|
177
|
+
@objc
|
|
178
|
+
private func inboxMessagesNewInboxMessagesListener() {
|
|
179
|
+
sendEvent("onInboxResponse", [
|
|
180
|
+
"messages": []
|
|
181
|
+
])
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@objc func inboxMessagesRefreshCompleteListener() {
|
|
185
|
+
if (self.refreshInboxPromise != nil) {
|
|
186
|
+
self.refreshInboxPromise!.resolve(true)
|
|
187
|
+
self.refreshInboxPromise = nil
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@objc
|
|
192
|
+
func onLog(level: LogLevel, subsystem: String, category: LoggerCategory, message: String) {
|
|
193
|
+
sendEvent("onLog", [
|
|
194
|
+
"level": level.rawValue,
|
|
195
|
+
"subsystem": subsystem,
|
|
196
|
+
"category": category.rawValue,
|
|
197
|
+
"message": message
|
|
198
|
+
])
|
|
199
|
+
}
|
|
146
200
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import SFMCSDK
|
|
3
|
+
import MarketingCloudSDK
|
|
4
|
+
|
|
5
|
+
class ExpoMarketingCloudSdkNotificationsDelegate : EXNotificationsDelegate {
|
|
6
|
+
@objc
|
|
7
|
+
public func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) async -> UIBackgroundFetchResult {
|
|
8
|
+
SFMCSdk.mp.setNotificationUserInfo(userInfo)
|
|
9
|
+
return UIBackgroundFetchResult.newData
|
|
10
|
+
}
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allboatsrise/expo-marketingcloudsdk",
|
|
3
3
|
"author": "All Boats Rise Inc.",
|
|
4
|
-
"version": "47.0.0-android.
|
|
4
|
+
"version": "47.0.0-android.26",
|
|
5
5
|
"description": "Expo module for Salesforce Marketing Cloud SDK",
|
|
6
6
|
"homepage": "https://github.com/allboatsrise/expo-marketingcloudsdk",
|
|
7
7
|
"keywords": [
|