@adobe/react-native-aepmessaging 1.0.0-beta.3 → 5.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/LICENSE +1 -1
- package/RCTAEPMessaging.podspec +2 -2
- package/README.md +185 -152
- package/android/build.gradle +8 -8
- package/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingModule.java +39 -47
- package/ios/src/RCTAEPMessaging.m +3 -3
- package/js/models/MessagingDelegate.d.ts +1 -1
- package/package.json +9 -6
- package/android/libs/messaging.aar +0 -0
- package/android/libs/optimize.aar +0 -0
package/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@ file or class name and description of purpose be included on the
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2023 Adobe
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/RCTAEPMessaging.podspec
CHANGED
|
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
|
|
10
10
|
s.homepage = "https://github.com/adobe/aepsdk-react-native"
|
|
11
11
|
|
|
12
12
|
s.license = "Apache 2.0 License"
|
|
13
|
-
s.platform = :ios, '
|
|
13
|
+
s.platform = :ios, '11.0'
|
|
14
14
|
|
|
15
15
|
s.source = { :git => "https://github.com/adobe/aepsdk-react-native.git", :tag => "#{s.version}" }
|
|
16
16
|
|
|
@@ -18,5 +18,5 @@ Pod::Spec.new do |s|
|
|
|
18
18
|
s.requires_arc = true
|
|
19
19
|
|
|
20
20
|
s.dependency "React"
|
|
21
|
-
s.dependency "AEPMessaging", "~>
|
|
21
|
+
s.dependency "AEPMessaging", "~> 4.0"
|
|
22
22
|
end
|
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
1
|
# React Native Adobe Experience Platform Messaging Extension
|
|
3
2
|
|
|
4
3
|
[](https://www.npmjs.com/package/@adobe/react-native-aepmessaging)
|
|
5
4
|
[](https://www.npmjs.com/package/@adobe/react-native-aepmessaging)
|
|
6
5
|
|
|
7
|
-
`@adobe/react-native-aepmessaging` is a wrapper around the iOS and Android [Adobe Journey Optimizer Messaging](https://
|
|
6
|
+
`@adobe/react-native-aepmessaging` is a wrapper around the iOS and Android [Adobe Journey Optimizer Messaging](https://developer.adobe.com/client-sdks/documentation/adobe-journey-optimizer) extension to allow for integration with React Native applications.
|
|
8
7
|
|
|
9
8
|
## Prerequisites
|
|
10
9
|
|
|
11
10
|
The messaging extension has the following peer dependenices, which must be installed prior to installing the messaging extension:
|
|
11
|
+
|
|
12
12
|
- [Core](../core/README.md)
|
|
13
13
|
- [Edge](../edge/README.md)
|
|
14
14
|
- [Edge Identity](../edgeidentity/README.md)
|
|
@@ -17,76 +17,62 @@ The messaging extension has the following peer dependenices, which must be insta
|
|
|
17
17
|
|
|
18
18
|
See [Requirements and Installation](https://github.com/adobe/aepsdk-react-native#requirements) instructions on the main page
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
Clone the `@adobe/react-native-aepmessaging` package from the `messaging` branch on [Github](https://github.com/adobe/aepsdk-react-native/tree/messaging). Place the Messaging package folder into app repo or directory of your choosing. Then you can install the package by running:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
cd MyReactApp
|
|
25
|
-
npm install {path to messaging package}
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## IOS Setup
|
|
20
|
+
Install the `@adobe/react-native-aepmessaging` package:
|
|
29
21
|
|
|
30
|
-
|
|
31
|
-
The In app Message APIs depends on the AEP Messaging iOS SDK v1.1.0-beta. This version is not yet published to the Cocoapods but is available in the public [github repository](https://github.com/adobe/aepsdk-messaging-ios/tree/staging). Add the following pod dependency in your applications Podfile under the application target.
|
|
22
|
+
NPM:
|
|
32
23
|
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
pod "AEPMessaging", :git => "https://github.com/adobe/aepsdk-messaging-ios.git", :branch => "staging"
|
|
36
|
-
end
|
|
24
|
+
```bash
|
|
25
|
+
npm install @adobe/react-native-aepmessaging
|
|
37
26
|
```
|
|
38
27
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
**Gradle setup for `@adobe/react-native-aepmessaging` v1.0.0-beta.2 with in-app messaging support**
|
|
42
|
-
AEPMessaging Android SDK v1.2.0-beta.2 with in-app messaging support is published to maven snapshots. In project level build.gradle file of Android project in your RN application add `maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }` in `allprojects -> repositories`.
|
|
43
|
-
|
|
28
|
+
Yarn:
|
|
44
29
|
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
google()
|
|
48
|
-
mavenCentral()
|
|
49
|
-
maven {
|
|
50
|
-
url "https://oss.sonatype.org/content/repositories/snapshots/"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
30
|
+
```bash
|
|
31
|
+
yarn add @adobe/react-native-aepmessaging
|
|
53
32
|
```
|
|
54
33
|
|
|
55
34
|
## Usage
|
|
56
35
|
|
|
57
|
-
### [Messaging](https://
|
|
36
|
+
### [Messaging](https://developer.adobe.com/client-sdks/documentation/adobe-journey-optimizer)
|
|
58
37
|
|
|
59
38
|
### Installing and registering the extension with the AEP Mobile Core
|
|
60
39
|
|
|
61
|
-
### Initialization
|
|
62
|
-
|
|
40
|
+
### Initialization
|
|
41
|
+
|
|
42
|
+
Initializing the SDK should be done in native code, additional documentation on how to initialize the SDK can be found [here](https://github.com/adobe/aepsdk-react-native#initializing).
|
|
43
|
+
|
|
44
|
+
Example:
|
|
63
45
|
|
|
64
|
-
|
|
46
|
+
iOS
|
|
65
47
|
|
|
66
|
-
iOS
|
|
67
48
|
```objectivec
|
|
68
49
|
@import AEPCore;
|
|
69
50
|
@import AEPLifecycle;
|
|
70
51
|
@import AEPEdge;
|
|
71
52
|
@import AEPEdgeIdentity;
|
|
72
53
|
@import AEPMessaging;
|
|
73
|
-
|
|
54
|
+
|
|
74
55
|
...
|
|
75
56
|
@implementation AppDelegate
|
|
76
57
|
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
77
|
-
[AEPMobileCore setLogLevel:
|
|
58
|
+
[AEPMobileCore setLogLevel: AEPLogLevelDebug];
|
|
59
|
+
[AEPMobileCore configureWithAppId:@"yourAppID"];
|
|
60
|
+
|
|
61
|
+
const UIApplicationState appState = application.applicationState;
|
|
62
|
+
|
|
78
63
|
[AEPMobileCore registerExtensions: @[AEPMobileEdgeIdentity.class, AEPMobileEdge.class, AEPMobileMessaging.class, AEPMobileOptimize.class] completion:^{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
];
|
|
64
|
+
if (appState != UIApplicationStateBackground) {
|
|
65
|
+
[AEPMobileCore lifecycleStart:nil}];
|
|
66
|
+
}
|
|
67
|
+
}];
|
|
83
68
|
return YES;
|
|
84
69
|
}
|
|
85
70
|
|
|
86
71
|
@end
|
|
87
72
|
```
|
|
88
73
|
|
|
89
|
-
Android
|
|
74
|
+
Android
|
|
75
|
+
|
|
90
76
|
```java
|
|
91
77
|
import com.adobe.marketing.mobile.AdobeCallback;
|
|
92
78
|
import com.adobe.marketing.mobile.InvalidInitException;
|
|
@@ -96,7 +82,6 @@ import com.adobe.marketing.mobile.MobileCore;
|
|
|
96
82
|
import com.adobe.marketing.mobile.Edge;
|
|
97
83
|
import com.adobe.marketing.mobile.edge.identity.Identity;
|
|
98
84
|
import com.adobe.marketing.mobile.Messaging;
|
|
99
|
-
import com.adobe.marketing.mobile.optimize.Optimize;
|
|
100
85
|
|
|
101
86
|
...
|
|
102
87
|
import android.app.Application;
|
|
@@ -109,286 +94,333 @@ public class MainApplication extends Application implements ReactApplication {
|
|
|
109
94
|
...
|
|
110
95
|
MobileCore.setApplication(this);
|
|
111
96
|
MobileCore.setLogLevel(LoggingMode.DEBUG);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
MobileCore.lifecycleStart(null);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
} catch (InvalidInitException e) {
|
|
125
|
-
...
|
|
126
|
-
}
|
|
97
|
+
MobileCore.configureWithAppID("yourAppID");
|
|
98
|
+
List<Class<? extends Extension>> extensions = Arrays.asList(
|
|
99
|
+
Edge.EXTENSION,
|
|
100
|
+
Identity.EXTENSION,
|
|
101
|
+
Messaging.EXTENSION,
|
|
102
|
+
Lifecycle.EXTENSION);
|
|
103
|
+
MobileCore.registerExtensions(extensions, o -> {
|
|
104
|
+
MobileCore.lifecycleStart(null);
|
|
105
|
+
});
|
|
127
106
|
}
|
|
128
|
-
}
|
|
107
|
+
}
|
|
129
108
|
```
|
|
130
109
|
|
|
131
110
|
### Importing the extension:
|
|
132
111
|
|
|
133
112
|
```javascript
|
|
134
|
-
import {
|
|
113
|
+
import {
|
|
114
|
+
Messaging,
|
|
115
|
+
MessagingDelegate,
|
|
116
|
+
MessagingEdgeEventType,
|
|
117
|
+
Message,
|
|
118
|
+
} from "@adobe/react-native-aepmessaging";
|
|
135
119
|
```
|
|
136
120
|
|
|
137
121
|
## API reference
|
|
122
|
+
|
|
138
123
|
### extensionVersion
|
|
124
|
+
|
|
139
125
|
Returns the version of the AEPMessaging extension
|
|
140
126
|
|
|
141
127
|
**Syntax**
|
|
128
|
+
|
|
142
129
|
```javascript
|
|
143
|
-
extensionVersion(): Promise<string
|
|
130
|
+
extensionVersion(): Promise<string>
|
|
144
131
|
```
|
|
145
132
|
|
|
146
133
|
**Example**
|
|
134
|
+
|
|
147
135
|
```javascript
|
|
148
|
-
Messaging.extensionVersion().then(version =>
|
|
136
|
+
Messaging.extensionVersion().then((version) =>
|
|
137
|
+
console.log("AdobeExperienceSDK: Messaging version: " + version)
|
|
138
|
+
);
|
|
149
139
|
```
|
|
150
140
|
|
|
151
141
|
## Configure Adobe Journey Optimizer
|
|
152
|
-
|
|
142
|
+
|
|
143
|
+
To configure Adobe Journey Optimizer Messaging in Launch follow the steps in [Configure Adobe Journey Optimizer](https://developer.adobe.com/client-sdks/documentation/adobe-journey-optimizer/#setup-adobe-journey-optimizer-extension)
|
|
153
144
|
|
|
154
145
|
## Push Notification Setup
|
|
155
|
-
|
|
156
|
-
|
|
146
|
+
|
|
147
|
+
Handling push notifications must be done in native (Android/iOS) code for the React Native app. To configure push notifications in the native project, follow the instructions provided for their respective platforms:
|
|
148
|
+
|
|
149
|
+
- [Apple - iOS push notification setup](https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns)
|
|
157
150
|
- [Google - Android push notification setup](https://firebase.google.com/docs/cloud-messaging/android/client)
|
|
158
151
|
|
|
159
152
|
## Push Messaging APIs usage
|
|
160
|
-
Push messaging APIs in the SDK must be called from the native Android/iOS project of React Native app.
|
|
161
153
|
|
|
162
|
-
|
|
154
|
+
The AEPMessaging extension's push messaging APIs must be called from the native Android/iOS project of React Native app.
|
|
155
|
+
|
|
156
|
+
###### [iOS API usage](https://github.com/adobe/aepsdk-messaging-ios/blob/main/Documentation/sources/usage.md)
|
|
157
|
+
|
|
158
|
+
##### [Android API usage](https://github.com/adobe/aepsdk-messaging-android/blob/main/Documentation/sources/api-usage.md)
|
|
163
159
|
|
|
164
|
-
|
|
165
|
-
In Android, [MessagingPushPayload](https://github.com/adobe/aepsdk-messaging-android/blob/main/Documentation/push/MessagingPushPayload.md#messagingpushpayload-usage) can be used for getting the notification attributes like title, body, and action. These are useful for push notification creation.
|
|
160
|
+
In Android, [MessagingPushPayload](https://github.com/adobe/aepsdk-messaging-android/blob/main/Documentation/sources/messaging-push-payload.md#messagingpushpayload-usage) can be used for getting the notification attributes like title, body, and action. These are useful for push notification creation.
|
|
166
161
|
|
|
167
162
|
## In-app messages API reference
|
|
163
|
+
|
|
168
164
|
### refreshInAppMessages
|
|
165
|
+
|
|
169
166
|
Initiates a network call to retrieve remote in-app message definitions.
|
|
170
167
|
|
|
171
168
|
**Syntax**
|
|
169
|
+
|
|
172
170
|
```javascript
|
|
173
171
|
refreshInAppMessages()
|
|
174
172
|
```
|
|
175
173
|
|
|
176
174
|
**Example**
|
|
175
|
+
|
|
177
176
|
```javascript
|
|
178
|
-
Messaging.refreshInAppMessages()
|
|
177
|
+
Messaging.refreshInAppMessages()
|
|
179
178
|
```
|
|
180
179
|
|
|
181
180
|
### setMessagingDelegate
|
|
182
|
-
|
|
181
|
+
|
|
182
|
+
Sets a custom `MessagingDelegate` in AEPCore to listen for Message lifecycle events.
|
|
183
183
|
|
|
184
184
|
**Syntax**
|
|
185
|
+
|
|
185
186
|
```javascript
|
|
186
|
-
setMessagingDelegate(delegate: MessagingDelegate)
|
|
187
|
+
setMessagingDelegate(delegate: MessagingDelegate)
|
|
187
188
|
```
|
|
188
189
|
|
|
189
190
|
**Example**
|
|
191
|
+
|
|
190
192
|
```javascript
|
|
191
193
|
const messagingDelegate = {
|
|
194
|
+
onShow(message: Message) {
|
|
195
|
+
// Action after message is displayed.
|
|
196
|
+
},
|
|
192
197
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
198
|
+
onDismiss(message: Message) {
|
|
199
|
+
// Action after message is dismissed.
|
|
200
|
+
},
|
|
196
201
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
202
|
+
shouldShowMessage(message: Message) {
|
|
203
|
+
return true; //Return true to show the Message else return false
|
|
204
|
+
},
|
|
200
205
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
urlLoaded(url: string, message: Message) {
|
|
206
|
-
// Action after message loads an URL
|
|
207
|
-
}
|
|
208
|
-
};
|
|
206
|
+
urlLoaded(url: string, message: Message) {
|
|
207
|
+
// Action after message loads an URL
|
|
208
|
+
},
|
|
209
|
+
};
|
|
209
210
|
|
|
210
|
-
|
|
211
|
+
Messaging.setMessagingDelegate(messagingDelegate)
|
|
211
212
|
```
|
|
212
213
|
|
|
213
214
|
### saveMessage
|
|
214
|
-
|
|
215
|
+
|
|
216
|
+
Natively caches the provided `Message` object in-memory. Cached `Message` objects can used at a later time to show the cached `Message` or perform other actions on the `Message` object. This function should be called from the `shouldShowMessage` function of the custom `MessagingDelegate`.
|
|
215
217
|
|
|
216
218
|
**Syntax**
|
|
219
|
+
|
|
217
220
|
```javascript
|
|
218
|
-
saveMessage(message: Message)
|
|
221
|
+
saveMessage(message: Message)
|
|
219
222
|
```
|
|
220
223
|
|
|
221
224
|
**Example**
|
|
225
|
+
|
|
222
226
|
```javascript
|
|
223
|
-
|
|
227
|
+
const messagingDelegate = {
|
|
228
|
+
|
|
229
|
+
shouldShowMessage(message: Message) {
|
|
230
|
+
Messaging.saveMessage(message)
|
|
231
|
+
return false;
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
};
|
|
224
235
|
```
|
|
225
236
|
|
|
226
237
|
## Handling In App Messages using Message Object
|
|
227
|
-
|
|
238
|
+
|
|
239
|
+
The `Message` object passed to the `MessagingDelegate` contains the following functions to handle a message:
|
|
228
240
|
|
|
229
241
|
### show
|
|
230
|
-
|
|
242
|
+
|
|
243
|
+
Signals to the `UIService` that the message should be shown.
|
|
231
244
|
|
|
232
245
|
**Syntax**
|
|
246
|
+
|
|
233
247
|
```javascript
|
|
234
|
-
show()
|
|
248
|
+
show()
|
|
235
249
|
```
|
|
236
250
|
|
|
237
251
|
**Example**
|
|
252
|
+
|
|
238
253
|
```javascript
|
|
239
|
-
var message: Message
|
|
240
|
-
message.show()
|
|
254
|
+
var message: Message
|
|
255
|
+
message.show()
|
|
241
256
|
```
|
|
242
257
|
|
|
243
258
|
### dismiss
|
|
244
|
-
|
|
259
|
+
|
|
260
|
+
Signals to the `UIService` that the message should be dismissed.
|
|
245
261
|
|
|
246
262
|
**Syntax**
|
|
263
|
+
|
|
247
264
|
```javascript
|
|
248
|
-
dismiss(suppressAutoTrack: ?boolean = false)
|
|
265
|
+
dismiss(((suppressAutoTrack: ?boolean) = false))
|
|
249
266
|
```
|
|
250
267
|
|
|
251
268
|
**Example**
|
|
269
|
+
|
|
252
270
|
```javascript
|
|
253
|
-
var message: Message
|
|
254
|
-
message.dismiss(true)
|
|
271
|
+
var message: Message
|
|
272
|
+
message.dismiss(true)
|
|
255
273
|
```
|
|
256
274
|
|
|
257
275
|
### track
|
|
258
|
-
|
|
276
|
+
|
|
277
|
+
Generates an Edge Event for the provided interaction and event type.
|
|
259
278
|
|
|
260
279
|
**Syntax**
|
|
280
|
+
|
|
261
281
|
```javascript
|
|
262
|
-
track(interaction: ?string, eventType: MessagingEdgeEventType)
|
|
282
|
+
track(interaction: ?string, eventType: MessagingEdgeEventType)
|
|
263
283
|
```
|
|
264
284
|
|
|
265
285
|
**Example**
|
|
286
|
+
|
|
266
287
|
```javascript
|
|
267
288
|
var message: Message;
|
|
268
|
-
message.track("sample text", MessagingEdgeEventType.IN_APP_DISMISS)
|
|
289
|
+
message.track("sample text", MessagingEdgeEventType.IN_APP_DISMISS)
|
|
269
290
|
```
|
|
270
291
|
|
|
271
292
|
### handleJavascriptMessage
|
|
293
|
+
|
|
272
294
|
Adds a handler for Javascript messages sent from the message's webview.
|
|
273
295
|
|
|
274
296
|
**Syntax**
|
|
297
|
+
|
|
275
298
|
```javascript
|
|
276
|
-
handleJavascriptMessage(name: string) : Promise<?any
|
|
299
|
+
handleJavascriptMessage(name: string) : Promise<?any>
|
|
277
300
|
```
|
|
278
301
|
|
|
279
302
|
**Example**
|
|
303
|
+
|
|
280
304
|
```javascript
|
|
281
305
|
var message: Message;
|
|
282
|
-
message.handleJavascriptMessage("test").then((data) => {
|
|
283
|
-
|
|
284
|
-
});
|
|
306
|
+
message.handleJavascriptMessage("test").then((data) => {})
|
|
285
307
|
```
|
|
286
308
|
|
|
287
309
|
### setAutoTrack
|
|
288
|
-
|
|
310
|
+
|
|
311
|
+
Enables/Disables autotracking for message events.
|
|
289
312
|
|
|
290
313
|
**Syntax**
|
|
314
|
+
|
|
291
315
|
```javascript
|
|
292
|
-
setAutoTrack(autoTrack: boolean)
|
|
316
|
+
setAutoTrack(autoTrack: boolean)
|
|
293
317
|
```
|
|
294
318
|
|
|
295
319
|
**Example**
|
|
320
|
+
|
|
296
321
|
```javascript
|
|
297
322
|
var message: Message;
|
|
298
|
-
message.setAutoTrack(true)
|
|
323
|
+
message.setAutoTrack(true)
|
|
299
324
|
```
|
|
300
325
|
|
|
301
326
|
### clear
|
|
302
|
-
Clears the reference to the in-memory cached Message object. This function must be called if a Message was saved by calling "Messaging.saveMessage" but no longer needed. Failure to call this function leads to memory leaks.
|
|
303
327
|
|
|
328
|
+
Clears the reference to the in-memory cached `Message` object. This function must be called if a message was saved by calling `Messaging.saveMessage` but no longer needed. Failure to call this function leads to memory leaks.
|
|
304
329
|
|
|
305
330
|
**Syntax**
|
|
331
|
+
|
|
306
332
|
```javascript
|
|
307
|
-
clear()
|
|
333
|
+
clear()
|
|
308
334
|
```
|
|
309
335
|
|
|
310
336
|
**Example**
|
|
337
|
+
|
|
311
338
|
```javascript
|
|
312
|
-
var message: Message
|
|
313
|
-
message.clear()
|
|
339
|
+
var message: Message
|
|
340
|
+
message.clear()
|
|
314
341
|
```
|
|
315
342
|
|
|
316
343
|
## Programatically control the display of in-app messages
|
|
317
|
-
App developers can now create a type MessagingDelegate in order to be alerted when specific events occur during the lifecycle of an in-app message.
|
|
318
344
|
|
|
319
|
-
|
|
320
|
-
```javascript
|
|
321
|
-
type MessagingDelegate = {
|
|
345
|
+
App developers can now create a type `MessagingDelegate` in order to be alerted when specific events occur during the lifecycle of an in-app message.
|
|
322
346
|
|
|
323
|
-
|
|
347
|
+
Definition of type `MessagingDelegate` is:
|
|
324
348
|
|
|
325
|
-
|
|
349
|
+
```javascript
|
|
350
|
+
type MessagingDelegate = {
|
|
351
|
+
onShow(message: Message): void,
|
|
326
352
|
|
|
327
|
-
|
|
353
|
+
onDismiss(message: Message): void,
|
|
328
354
|
|
|
329
|
-
|
|
355
|
+
shouldShowMessage(message: Message): boolean,
|
|
356
|
+
|
|
357
|
+
urlLoaded(url: string, message: Message): void,
|
|
330
358
|
};
|
|
331
359
|
```
|
|
332
|
-
|
|
360
|
+
|
|
361
|
+
Objects of type `MessagingDelegate` can be created as shown below:
|
|
362
|
+
|
|
333
363
|
```javascript
|
|
334
364
|
const messagingDelegate = {
|
|
365
|
+
onShow(message: Message) {
|
|
366
|
+
// Action after message is displayed.
|
|
367
|
+
},
|
|
335
368
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
369
|
+
onDismiss(message: Message) {
|
|
370
|
+
// Action after message is dismissed.
|
|
371
|
+
},
|
|
339
372
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
373
|
+
shouldShowMessage(message: Message) {
|
|
374
|
+
return true; //Return true to show the Message else return false
|
|
375
|
+
},
|
|
343
376
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
urlLoaded(url: string, message: Message) {
|
|
349
|
-
// Action after message loads an URL
|
|
350
|
-
}
|
|
351
|
-
};
|
|
377
|
+
urlLoaded(url: string, message: Message) {
|
|
378
|
+
// Action after message loads an URL
|
|
379
|
+
},
|
|
380
|
+
};
|
|
352
381
|
```
|
|
353
382
|
|
|
354
383
|
### Controlling when the message should be shown to the end user.
|
|
355
|
-
|
|
384
|
+
|
|
385
|
+
If a `MessagingDelegate` has been set, the delegate's `shouldShowMessage` function will be called prior to displaying an in-app message for which the end user has qualified. The developer is responsible for returning true if the message should be shown, or false if the message should be suppressed.
|
|
356
386
|
|
|
357
387
|
Below is an example of when the developer may choose to suppress an in-app message due to the status of some other workflow within the app:
|
|
388
|
+
|
|
358
389
|
```javascript
|
|
359
390
|
function shouldShowMessage(message: Message): boolean {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
391
|
+
if (someOtherWorkflowStatus == "inProgress") {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
363
394
|
|
|
364
|
-
|
|
395
|
+
return true;
|
|
365
396
|
}
|
|
366
397
|
```
|
|
367
398
|
|
|
368
|
-
Another option for the developer is to store a reference to the Message object, and call the show
|
|
399
|
+
Another option for the developer is to store a reference to the `Message` object, and call the `show` function on it at a later time. To use this functionality, app developers can call `Messaging.saveMessage(message)` from the `shouldShowMessage` of the `MessagingDelegate` for caching the Message on the native side of the RN AEPMessaging package.
|
|
369
400
|
Continuing with the above example, the developer has stored the message that was triggered initially, and chooses to show it upon completion of the other workflow:
|
|
370
401
|
|
|
371
402
|
```javascript
|
|
372
403
|
var cachedMessage: Message;
|
|
373
404
|
|
|
374
405
|
function otherWorkflowFinished() {
|
|
375
|
-
|
|
376
|
-
|
|
406
|
+
anotherWorkflowStatus = "complete";
|
|
407
|
+
cachedMessage.show();
|
|
377
408
|
}
|
|
378
409
|
|
|
379
410
|
function shouldShowMessage(message: Message): boolean {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
411
|
+
if (anotherWorkflowStatus === "inProgress") {
|
|
412
|
+
// store the current message for later use
|
|
413
|
+
Messaging.saveMessage(message);
|
|
414
|
+
cachedMessage = message;
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
386
417
|
|
|
387
|
-
|
|
418
|
+
return true;
|
|
388
419
|
}
|
|
389
420
|
```
|
|
390
421
|
|
|
391
|
-
**Important:** If the cached message is no longer needed after being used, free up the references to the Message object by calling
|
|
422
|
+
**Important:** If the cached message is no longer needed after being used, free up the references to the `Message` object by calling `message.clearMessage()` to prevent memory leaks. In above example after displaying the in app message using cached message object if it is no longer needed then it should be cleared as shown below.
|
|
423
|
+
|
|
392
424
|
```javascript
|
|
393
425
|
function otherWorkflowFinished() {
|
|
394
426
|
anotherWorkflowStatus = "complete";
|
|
@@ -396,3 +428,4 @@ function otherWorkflowFinished() {
|
|
|
396
428
|
currentMessage.clearMessage();
|
|
397
429
|
}
|
|
398
430
|
```
|
|
431
|
+
|
package/android/build.gradle
CHANGED
|
@@ -2,7 +2,6 @@ buildscript {
|
|
|
2
2
|
repositories {
|
|
3
3
|
google()
|
|
4
4
|
mavenCentral()
|
|
5
|
-
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
dependencies {
|
|
@@ -12,13 +11,16 @@ buildscript {
|
|
|
12
11
|
|
|
13
12
|
apply plugin: 'com.android.library'
|
|
14
13
|
|
|
14
|
+
def safeExtGet(prop, fallback) {
|
|
15
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
16
|
+
}
|
|
17
|
+
|
|
15
18
|
android {
|
|
16
|
-
compileSdkVersion
|
|
17
|
-
// buildToolsVersion "23.0.1"
|
|
19
|
+
compileSdkVersion safeExtGet('compileSdkVersion', 33)
|
|
18
20
|
|
|
19
21
|
defaultConfig {
|
|
20
|
-
minSdkVersion 19
|
|
21
|
-
targetSdkVersion
|
|
22
|
+
minSdkVersion safeExtGet('minSdkVersion', 19)
|
|
23
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 33)
|
|
22
24
|
versionCode 1
|
|
23
25
|
versionName "1.0"
|
|
24
26
|
}
|
|
@@ -30,11 +32,9 @@ android {
|
|
|
30
32
|
repositories {
|
|
31
33
|
google()
|
|
32
34
|
mavenCentral()
|
|
33
|
-
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
dependencies {
|
|
37
|
-
api "com.adobe.marketing.mobile:
|
|
38
|
-
api "com.adobe.marketing.mobile:messaging:1.3.0-beta-3-SNAPSHOT"
|
|
38
|
+
api "com.adobe.marketing.mobile:messaging:[2.1.0, 3.0["
|
|
39
39
|
implementation "com.facebook.react:react-native:+"
|
|
40
40
|
}
|
|
@@ -22,9 +22,8 @@ import com.adobe.marketing.mobile.Message;
|
|
|
22
22
|
import com.adobe.marketing.mobile.Messaging;
|
|
23
23
|
import com.adobe.marketing.mobile.MessagingEdgeEventType;
|
|
24
24
|
import com.adobe.marketing.mobile.MobileCore;
|
|
25
|
-
import com.adobe.marketing.mobile.services.
|
|
25
|
+
import com.adobe.marketing.mobile.services.MessagingDelegate;
|
|
26
26
|
import com.adobe.marketing.mobile.services.ui.FullscreenMessage;
|
|
27
|
-
import com.adobe.marketing.mobile.services.ui.FullscreenMessageDelegate;
|
|
28
27
|
import com.facebook.react.bridge.Arguments;
|
|
29
28
|
import com.facebook.react.bridge.Promise;
|
|
30
29
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
@@ -37,7 +36,7 @@ import java.util.HashMap;
|
|
|
37
36
|
import java.util.Map;
|
|
38
37
|
import java.util.concurrent.CountDownLatch;
|
|
39
38
|
|
|
40
|
-
public final class RCTAEPMessagingModule extends ReactContextBaseJavaModule implements
|
|
39
|
+
public final class RCTAEPMessagingModule extends ReactContextBaseJavaModule implements MessagingDelegate {
|
|
41
40
|
|
|
42
41
|
private static final String TAG = "RCTAEPMessagingModule";
|
|
43
42
|
private final Map<String, Message> messageCache;
|
|
@@ -81,7 +80,7 @@ public final class RCTAEPMessagingModule extends ReactContextBaseJavaModule impl
|
|
|
81
80
|
@ReactMethod
|
|
82
81
|
public void setMessagingDelegate() {
|
|
83
82
|
MobileCore.log(VERBOSE, TAG, "setMessagingDelegate is called");
|
|
84
|
-
|
|
83
|
+
MobileCore.setMessagingDelegate(this);
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
@ReactMethod
|
|
@@ -164,7 +163,7 @@ public final class RCTAEPMessagingModule extends ReactContextBaseJavaModule impl
|
|
|
164
163
|
public void setAutoTrack(final String messageId, final boolean autoTrack) {
|
|
165
164
|
if (messageId != null && messageCache.get(messageId) != null) {
|
|
166
165
|
MobileCore.log(VERBOSE, TAG, String.format("setAutoTrack is called with message id: %s and autoTrack: %b", messageId, autoTrack));
|
|
167
|
-
messageCache.get(messageId).autoTrack
|
|
166
|
+
messageCache.get(messageId).setAutoTrack(autoTrack);
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
169
|
|
|
@@ -183,8 +182,8 @@ public final class RCTAEPMessagingModule extends ReactContextBaseJavaModule impl
|
|
|
183
182
|
final Message message = (Message) fullscreenMessage.getParent();
|
|
184
183
|
if (message != null) {
|
|
185
184
|
Map<String, String> data = new HashMap<>();
|
|
186
|
-
data.put("id", message.
|
|
187
|
-
data.put("autoTrack", String.valueOf(message.
|
|
185
|
+
data.put("id", message.getId());
|
|
186
|
+
data.put("autoTrack", String.valueOf(message.getAutoTrack()));
|
|
188
187
|
emitEvent("onShow", data);
|
|
189
188
|
}
|
|
190
189
|
}
|
|
@@ -195,55 +194,48 @@ public final class RCTAEPMessagingModule extends ReactContextBaseJavaModule impl
|
|
|
195
194
|
final Message message = (Message) fullscreenMessage.getParent();
|
|
196
195
|
if (message != null) {
|
|
197
196
|
Map<String, String> data = new HashMap<>();
|
|
198
|
-
data.put("id", message.
|
|
199
|
-
data.put("autoTrack", String.valueOf(message.
|
|
197
|
+
data.put("id", message.getId());
|
|
198
|
+
data.put("autoTrack", String.valueOf(message.getAutoTrack()));
|
|
200
199
|
emitEvent("onDismiss", data);
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
202
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
MobileCore.log(VERBOSE, TAG, String.format("overrideUrlLoad is called with url: (%s)",
|
|
203
|
+
@Override
|
|
204
|
+
public boolean shouldShowMessage(final FullscreenMessage fullscreenMessage) {
|
|
205
|
+
MobileCore.log(VERBOSE, TAG, "shouldShowMessage is called");
|
|
206
|
+
final Message message = (Message) fullscreenMessage.getParent();
|
|
207
|
+
if (message != null) {
|
|
208
|
+
Map<String, String> data = new HashMap<>();
|
|
209
|
+
data.put("id", message.getId());
|
|
210
|
+
data.put("autoTrack", String.valueOf(message.getAutoTrack()));
|
|
211
|
+
emitEvent("shouldShowMessage", data);
|
|
212
|
+
//Latch stops the thread until the shouldShowMessage value is received from the JS side on thread dedicated to run JS code. The function called from JS that resumes the thread is "shouldShowMessage".
|
|
213
|
+
MobileCore.log(VERBOSE, TAG, "shouldShowMessage: Thread is locked.");
|
|
214
|
+
try {
|
|
215
|
+
latch.await();
|
|
216
|
+
} catch (final InterruptedException e) {
|
|
217
|
+
MobileCore.log(LoggingMode.ERROR, TAG, String.format("CountDownLatch await Interrupted: (%s)", e.getLocalizedMessage()));
|
|
218
|
+
}
|
|
219
|
+
MobileCore.log(VERBOSE, TAG, "shouldShowMessage: Thread is resumed.");
|
|
220
|
+
if (shouldSaveMessage) {
|
|
221
|
+
messageCache.put(message.getId(), message);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return shouldShowMessage;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
@Override
|
|
228
|
+
public void urlLoaded(String url, FullscreenMessage fullscreenMessage) {
|
|
229
|
+
MobileCore.log(VERBOSE, TAG, String.format("overrideUrlLoad is called with url: (%s)", url));
|
|
231
230
|
final Message message = (Message) fullscreenMessage.getParent();
|
|
232
231
|
if (message != null) {
|
|
233
232
|
Map<String, String> data = new HashMap<>();
|
|
234
|
-
data.put("id", message.
|
|
235
|
-
data.put("autoTrack", String.valueOf(message.
|
|
236
|
-
data.put("url",
|
|
237
|
-
emitEvent("shouldShowMessage", data);
|
|
233
|
+
data.put("id", message.getId());
|
|
234
|
+
data.put("autoTrack", String.valueOf(message.getAutoTrack()));
|
|
235
|
+
data.put("url", url);
|
|
238
236
|
emitEvent("urlLoaded", data);
|
|
239
237
|
}
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
@Override
|
|
244
|
-
public void onShowFailure() {
|
|
245
|
-
MobileCore.log(VERBOSE, TAG, "onShowFailure is called.");
|
|
246
|
-
}
|
|
238
|
+
}
|
|
247
239
|
|
|
248
240
|
/**
|
|
249
241
|
* Emits an event along with data to be handled by the Javascript
|
|
@@ -133,7 +133,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(shouldShowMessage: (BOOL) shouldShowMessa
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
//MARK: - AEPMessagingDelegate functions.
|
|
136
|
-
- (void)
|
|
136
|
+
- (void) onDismiss:(id<AEPShowable> _Nonnull) message {
|
|
137
137
|
AEPFullscreenMessage * fullscreenMessage = (AEPFullscreenMessage *) message;
|
|
138
138
|
AEPMessage * messageObj = (AEPMessage *) fullscreenMessage.settings.parent;
|
|
139
139
|
if(messageObj) {
|
|
@@ -141,7 +141,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(shouldShowMessage: (BOOL) shouldShowMessa
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
- (void)
|
|
144
|
+
- (void) onShow:(id<AEPShowable> _Nonnull)message {
|
|
145
145
|
AEPFullscreenMessage * fullscreenMessage = (AEPFullscreenMessage *) message;
|
|
146
146
|
AEPMessage * messageObj = (AEPMessage *) fullscreenMessage.settings.parent;
|
|
147
147
|
if(messageObj) {
|
|
@@ -149,7 +149,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(shouldShowMessage: (BOOL) shouldShowMessa
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
- (BOOL)
|
|
152
|
+
- (BOOL) shouldShowMessage:(id<AEPShowable> _Nonnull)message {
|
|
153
153
|
AEPFullscreenMessage * fullscreenMessage = (AEPFullscreenMessage *) message;
|
|
154
154
|
AEPMessage * messageObj = (AEPMessage *) fullscreenMessage.settings.parent;
|
|
155
155
|
if(messageObj) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/react-native-aepmessaging",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Adobe Experience Platform support for React Native apps.",
|
|
5
|
-
"homepage": "https://
|
|
5
|
+
"homepage": "https://developer.adobe.com/client-sdks/documentation/",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "./ts/index.ts",
|
|
8
8
|
"scripts": {
|
|
@@ -27,13 +27,16 @@
|
|
|
27
27
|
"name": "Adobe Experience Platform SDK Team"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@adobe/react-native-aepcore": "^
|
|
31
|
-
"@adobe/react-native-aepedge": "^
|
|
32
|
-
"@adobe/react-native-aepedgeidentity": "^
|
|
30
|
+
"@adobe/react-native-aepcore": "^5.0.0",
|
|
31
|
+
"@adobe/react-native-aepedge": "^5.0.0",
|
|
32
|
+
"@adobe/react-native-aepedgeidentity": "^5.0.0",
|
|
33
33
|
"react-native": ">=0.60.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"
|
|
38
|
+
"installConfig": {
|
|
39
|
+
"hoistingLimits": "dependencies"
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "7c28b79c996a51d9d5048b0bfd60a5df4cbc8cc8"
|
|
39
42
|
}
|
|
Binary file
|
|
Binary file
|