Skip to content

Commit 2ffe391

Browse files
authored
Merge pull request #44 from CleverTap/develop
SDK-2803-Push primer support
2 parents ce52e83 + 9354664 commit 2ffe391

28 files changed

+814
-26
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Change Log
22
==========
33

4+
Version 2.4.0 *(15 May, 2023)*
5+
-------------------------------------------
6+
- Adds below new public APIs to support [CleverTap Android SDK v5.0.0](https://github.com/CleverTap/clevertap-android-sdk/releases/tag/corev5.0.0_ptv1.0.9)
7+
- `CleverTapBinding.IsPushPermissionGranted()`, `CleverTapBinding.PromptPushPrimer(object)`, `CleverTapBinding.PromptForPushPermission(boolean)`
8+
- Adds push permission callback method `CleverTapOnPushPermissionResponseCallback` which returns true/false after user allows/denies the notification permission.
9+
- Adds `CleverTapInAppNotificationShowCallback` to handle InApp notification shown - Only for Android.
10+
- Adds `DeleteInboxMessagesForIDs` for deleting multiple app inbox messages by passing a collection of messageIDs.
11+
- Adds `DeleteInboxMessageForID` for deleting single app inbox messages by passing a messageID.
12+
- Adds `MarkReadInboxMessagesForIDs` for marking multiple app inbox messages as read messages by passing a collection of messageIDs.
13+
- Adds `MarkReadInboxMessageForID` for marking an app inbox messages as read message by passing a messageID.
14+
415
Version 2.3.1 *(13 April, 2023)*
516
-------------------------------------------
617
- Updated to [CleverTap Android SDK v4.6.9](https://github.com/CleverTap/clevertap-android-sdk/releases/tag/corev4.6.9)

CleverTapUnityPlugin.unitypackage

-433 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Plugin/CleverTapUnity/CleverTapUnity-Scripts/CleverTapBinding.cs

+77-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace CleverTap {
1212
public class CleverTapBinding : MonoBehaviour {
1313

14-
public const string Version = "2.3.1";
14+
public const string Version = "2.4.0";
1515

1616
#if UNITY_IOS
1717
void Start() {
@@ -183,6 +183,9 @@ void Start() {
183183
[System.Runtime.InteropServices.DllImport("__Internal")]
184184
private static extern void CleverTap_markReadInboxMessageForID(string messageId);
185185

186+
[System.Runtime.InteropServices.DllImport("__Internal")]
187+
private static extern void CleverTap_markReadInboxMessagesForIDs(string[] messageIds,int arrLength);
188+
186189
[System.Runtime.InteropServices.DllImport("__Internal")]
187190
private static extern void CleverTap_recordInboxNotificationViewedEventForID(string messageId);
188191

@@ -234,6 +237,15 @@ void Start() {
234237
[System.Runtime.InteropServices.DllImport("__Internal")]
235238
private static extern bool CleverTap_getFeatureFlag(string key, bool defaultValue);
236239

240+
[System.Runtime.InteropServices.DllImport("__Internal")]
241+
private static extern void CleverTap_promptForPushPermission(bool showFallbackSettings);
242+
243+
[System.Runtime.InteropServices.DllImport("__Internal")]
244+
private static extern void CleverTap_promptPushPrimer(string json);
245+
246+
[System.Runtime.InteropServices.DllImport("__Internal")]
247+
private static extern void CleverTap_isPushPermissionGranted();
248+
237249
public static void LaunchWithCredentials(string accountID, string token) {
238250
CleverTap_launchWithCredentials(accountID, token);
239251
}
@@ -517,6 +529,11 @@ public static void MarkReadInboxMessageForID(string messageId) {
517529
CleverTap_markReadInboxMessageForID(messageId);
518530
}
519531

532+
public static void MarkReadInboxMessagesForIDs(string[] messageIds) {
533+
int arrLength = messageIds.Length;
534+
CleverTap_MarkReadInboxMessagesForIDs(messageIds, arrLength);
535+
}
536+
520537
public static void RecordInboxNotificationViewedEventForID(string messageId) {
521538
CleverTap_recordInboxNotificationViewedEventForID(messageId);
522539
}
@@ -610,6 +627,19 @@ public static bool GetFeatureFlag(string key, bool defaultValue) {
610627
return CleverTap_getFeatureFlag(key, defaultValue);
611628
}
612629

630+
public static void PromptPushPrimer(Dictionary<string, object> json) {
631+
var jsonString = Json.Serialize(json);
632+
CleverTap_promptPushPrimer(jsonString);
633+
}
634+
635+
636+
public static void PromptForPushPermission(bool showFallbackSettings) {
637+
CleverTap_promptForPushPermission(showFallbackSettings);
638+
}
639+
640+
public static void IsPushPermissionGranted() {
641+
CleverTap_isPushPermissionGranted();
642+
}
613643

614644
#elif UNITY_ANDROID
615645
private static AndroidJavaObject unityActivity;
@@ -864,6 +894,7 @@ public static void ProfileAddMultiValueForKey(string key, string val) {
864894
public static void ProfileRemoveMultiValueForKey(string key, string val) {
865895
CleverTap.Call("profileRemoveMultiValueForKey", key, val);
866896
}
897+
867898
public static void RecordScreenView(string screenName) {
868899
CleverTap.Call("recordScreenView", screenName);
869900
}
@@ -969,13 +1000,36 @@ public static int GetInboxMessageCount(){
9691000
}
9701001

9711002
public static void DeleteInboxMessagesForIDs(string[] messageIds) {
972-
// no-op for Android
1003+
CleverTap.Call("deleteInboxMessagesForIDs", messageIds);
1004+
}
1005+
1006+
public static void DeleteInboxMessageForID(string messageId) {
1007+
CleverTap.Call("deleteInboxMessageForId", messageId);
1008+
}
1009+
1010+
public static void MarkReadInboxMessagesForIDs(string[] messageIds) {
1011+
CleverTap.Call("markReadInboxMessagesForIDs", messageIds);
1012+
}
1013+
1014+
public static void MarkReadInboxMessageForID(string messageId) {
1015+
CleverTap.Call("markReadInboxMessageForId", messageId);
9731016
}
9741017

9751018
public static int GetInboxMessageUnreadCount(){
9761019
return CleverTap.Call<int>("getInboxMessageUnreadCount");
9771020
}
9781021

1022+
public static void PromptPushPrimer(Dictionary<string, object> details){
1023+
CleverTap.Call("promptPushPrimer", Json.Serialize(details));
1024+
}
1025+
1026+
public static void PromptForPushPermission(bool showFallbackSettings){
1027+
CleverTap.Call("promptForPushPermission", showFallbackSettings);
1028+
}
1029+
1030+
public static bool IsPushPermissionGranted(){
1031+
return CleverTap.Call<bool>("isPushPermissionGranted");
1032+
}
9791033
#else
9801034

9811035
// Empty implementations of the API, in case the application is being compiled for a platform other than iOS or Android.
@@ -1165,6 +1219,27 @@ public static int GetInboxMessageCount(){
11651219
public static int GetInboxMessageUnreadCount(){
11661220
return -1;
11671221
}
1222+
1223+
public static void DeleteInboxMessagesForIDs(string[] messageIds) {
1224+
}
1225+
1226+
public static void DeleteInboxMessageForID(string messageId) {
1227+
}
1228+
1229+
public static void MarkReadInboxMessagesForIDs(string[] messageIds) {
1230+
}
1231+
1232+
public static void MarkReadInboxMessageForID(string messageId) {
1233+
}
1234+
1235+
public static void PromptPushPrimer(string json){
1236+
}
1237+
1238+
public static void PromptForPushPermission(bool showFallbackSettings){
1239+
}
1240+
1241+
public static void IsPushPermissionGranted(){
1242+
}
11681243
#endif
11691244
}
11701245
}

Plugin/CleverTapUnity/CleverTapUnity-Scripts/CleverTapUnity.cs

+67-7
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,58 @@ void Awake(){
6767
// CleverTapBinding.RecordChargedEventWithDetailsAndItems(chargeDetails, items);
6868

6969
// CleverTapBinding.RecordEvent("testEventPushAmp");
70+
//Push Primer APIs usages
71+
72+
// CleverTapBinding.IsPushPermissionGranted();
73+
// Debug.Log("isPushPermissionGranted"+ isPushPermissionGranted);
74+
75+
// Dictionary<string, object> item = new Dictionary<string, object>();
76+
// item.Add("inAppType", "half-interstitial");
77+
// item.Add("titleText", "Get Notified");
78+
// item.Add("messageText", "Please enable notifications on your device to use Push Notifications.");
79+
// item.Add("followDeviceOrientation", true);
80+
// item.Add("positiveBtnText", "Allow");
81+
// item.Add("negativeBtnText", "Cancel");
82+
// item.Add("backgroundColor", "#FFFFFF");
83+
// item.Add("btnBorderColor", "#0000FF");
84+
// item.Add("titleTextColor", "#0000FF");
85+
// item.Add("messageTextColor", "#000000");
86+
// item.Add("btnTextColor", "#FFFFFF");
87+
// item.Add("btnBackgroundColor", "#0000FF");
88+
// item.Add("imageUrl", "https://icons.iconarchive.com/icons/treetog/junior/64/camera-icon.png");
89+
// item.Add("btnBorderRadius", "2");
90+
// item.Add("fallbackToSettings", true);
91+
// CleverTapBinding.PromptPushPrimer(item);
92+
93+
// CleverTapBinding.PromptForPushPermission(false);
94+
95+
//Push Primer APIs usages
96+
97+
// bool isPushPermissionGranted = CleverTapBinding.IsPushPermissionGranted();
98+
// Debug.Log("isPushPermissionGranted"+ isPushPermissionGranted);
99+
100+
// Dictionary<string, object> item = new Dictionary<string, object>();
101+
// item.Add("inAppType", "half-interstitial");
102+
// item.Add("titleText", "Get Notified");
103+
// item.Add("messageText", "Please enable notifications on your device to use Push Notifications.");
104+
// item.Add("followDeviceOrientation", true);
105+
// item.Add("positiveBtnText", "Allow");
106+
// item.Add("negativeBtnText", "Cancel");
107+
// item.Add("backgroundColor", "#FFFFFF");
108+
// item.Add("btnBorderColor", "#0000FF");
109+
// item.Add("titleTextColor", "#0000FF");
110+
// item.Add("messageTextColor", "#000000");
111+
// item.Add("btnTextColor", "#FFFFFF");
112+
// item.Add("btnBackgroundColor", "#0000FF");
113+
// item.Add("imageUrl", "https://icons.iconarchive.com/icons/treetog/junior/64/camera-icon.png");
114+
// item.Add("btnBorderRadius", "2");
115+
// item.Add("fallbackToSettings", true);
116+
// CleverTapBinding.PromptPushPrimer(item);
117+
118+
// CleverTapBinding.PromptForPushPermission(false);
70119

71120
// Push Templates APIs usages
72121
// CleverTapBinding.RecordEvent("Send Basic Push");
73-
74122
// CleverTapBinding.RecordEvent("Send Carousel Push");
75123
// CleverTapBinding.RecordEvent("Send Manual Carousel Push");
76124
// CleverTapBinding.RecordEvent("Send Filmstrip Carousel Push");
@@ -89,14 +137,14 @@ void Awake(){
89137
// CleverTapBinding.RecordEvent("Send Input Box CTA DOC false");
90138
// CleverTapBinding.RecordEvent("Send Input Box Reminder DOC true");
91139
// CleverTapBinding.RecordEvent("Send Input Box Reminder DOC false");
92-
140+
93141
//==========[Testing Newly added Clevertap APIs]============================================
94142
if (CLEVERTAP_ENABLE_PERSONALIZATION) {
95143
CleverTapBinding.EnablePersonalization();
96144
}
97145
#endif
98146
}
99-
147+
100148
void Start() {}
101149

102150
// handle deep link url
@@ -122,7 +170,7 @@ void CleverTapProfileInitializedCallback(string message) {
122170
}
123171

124172
// called when the user profile is updated as a result of a server sync
125-
/**
173+
/**
126174
returns dict in the form:
127175
{
128176
"profile":{"<property1>":{"oldValue":<value>, "newValue":<value>}, ...},
@@ -150,8 +198,8 @@ void CleverTapProfileUpdatesCallback(string message) {
150198
} catch {
151199
Debug.LogError("unable to parse json");
152200
}
153-
}
154-
201+
}
202+
155203
// returns the data associated with the push notification
156204
void CleverTapPushOpenedCallback(string message) {
157205
Debug.Log("unity received push opened: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
@@ -178,6 +226,17 @@ void CleverTapInAppNotificationDismissedCallback(string message) {
178226
Debug.Log("unity received inapp notification dismissed: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
179227
}
180228

229+
// returns the custom data associated with an in-app notification click
230+
void CleverTapInAppNotificationShowCallback(string message) {
231+
Debug.Log("unity received inapp notification onShow(): " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
232+
}
233+
234+
// returns the status of push permission response after it's granted/denied
235+
void CleverTapOnPushPermissionResponseCallback(string message) {
236+
//Ensure to create call the `CreateNotificationChannel` once notification permission is granted to register for receiving push notifications for Android 13+ devices.
237+
Debug.Log("unity received push permission response: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
238+
}
239+
181240
// returns when an in-app notification is dismissed by a call to action with custom extras
182241
void CleverTapInAppNotificationButtonTapped(string message) {
183242
Debug.Log("unity received inapp notification button tapped: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
@@ -196,10 +255,11 @@ void CleverTapInboxMessagesDidUpdateCallback(){
196255
void CleverTapInboxCustomExtrasButtonSelect(string message) {
197256
Debug.Log("unity received inbox message button with custom extras select: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
198257
}
258+
199259
// returns on the click of app inbox message with a string of the inbox payload along with page index and button index
200260
void CleverTapInboxItemClicked(string message)
201261
{
202-
Debug.Log("unity received inbox message selected callback: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
262+
Debug.Log("unity received inbox message clicked callback: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
203263
}
204264

205265
// returns native display units data

Plugin/CleverTapUnity/Editor/CleverTapUnityDependencies.xml

+2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@
2020
<androidPackage spec="androidx.recyclerview:recyclerview:1.2.1" />
2121

2222
<androidPackage spec="com.android.installreferrer:installreferrer:2.2" />
23+
24+
<androidPackage spec="org.jetbrains.kotlin:kotlin-stdlib:1.5.31" />
2325
</androidPackages>
2426
</dependencies>

Plugin/CleverTapUnity/iOS/CleverTapBinding.m

+18
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ void CleverTap_markReadInboxMessageForID(const char* messageId) {
458458
[[CleverTapUnityManager sharedInstance] markReadInboxMessageForID:clevertap_stringToNSString(messageId)];
459459
}
460460

461+
void CleverTap_markReadInboxMessagesForIDs(const char* messageIds[], int size) {
462+
[[CleverTapUnityManager sharedInstance] markReadInboxMessagesForIDs:clevertap_NSArrayFromArray(messageIds, size)];
463+
}
464+
461465
void CleverTap_recordInboxNotificationViewedEventForID(const char* messageId) {
462466
[[CleverTapUnityManager sharedInstance] recordInboxNotificationViewedEventForID:clevertap_stringToNSString(messageId)];
463467
}
@@ -565,4 +569,18 @@ void CleverTap_discardInAppNotifications() {
565569

566570
void CleverTap_resumeInAppNotifications() {
567571
[[CleverTapUnityManager sharedInstance] resumeInAppNotifications];
572+
}
573+
574+
#pragma mark - Push Primer
575+
void CleverTap_promptPushPrimer(const char* json) {
576+
NSMutableDictionary *jsonDict = clevertap_dictFromJsonString(json);
577+
[[CleverTapUnityManager sharedInstance] promptPushPrimer: jsonDict];
578+
}
579+
580+
void CleverTap_promptForPushPermission(const BOOL showFallbackSettings) {
581+
[[CleverTapUnityManager sharedInstance] promptForPushPermission: showFallbackSettings];
582+
}
583+
584+
void CleverTap_isPushPermissionGranted() {
585+
return [[CleverTapUnityManager sharedInstance] isPushPermissionGranted];
568586
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#import <Foundation/Foundation.h>
2+
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
typedef NS_ENUM(NSUInteger, CTLocalInAppType) {
6+
ALERT,
7+
HALF_INTERSTITIAL
8+
};
9+
10+
/*!
11+
12+
@abstract
13+
The `CTLocalInApp` represents the builder class to display local in-app.
14+
*/
15+
@interface CTLocalInApp : NSObject
16+
17+
/*!
18+
@method
19+
20+
@abstract
21+
Initializes and returns an instance of the CTLocalInApp.
22+
23+
@discussion
24+
This method have all parameters as required fields.
25+
26+
@param inAppType the local in-app type, ALERT or HALF_INTERSTITIAL
27+
@param titleText in-app title text
28+
@param messageText in-app message text
29+
@param followDeviceOrientation If YES, in-app will display in both orientation. If NO, in-app will not display in landscape orientation
30+
@param positiveBtnText in-app positive button text, eg "Allow"
31+
@param negativeBtnText in-app negative button text, eg "Cancel"
32+
*/
33+
- (instancetype)initWithInAppType:(CTLocalInAppType)inAppType
34+
titleText:(NSString *)titleText
35+
messageText:(NSString *)messageText
36+
followDeviceOrientation:(BOOL)followDeviceOrientation
37+
positiveBtnText:(NSString *)positiveBtnText
38+
negativeBtnText:(NSString *)negativeBtnText;
39+
40+
/**
41+
Returns NSDictionary having all local in-app settings as key-value pair.
42+
*/
43+
- (NSDictionary *)getLocalInAppSettings;
44+
45+
/* -----------------
46+
* Optional methods.
47+
* -----------------
48+
*/
49+
- (void)setBackgroundColor:(NSString *)backgroundColor;
50+
- (void)setTitleTextColor:(NSString *)titleTextColor;
51+
- (void)setMessageTextColor:(NSString *)messageTextColor;
52+
- (void)setBtnBorderRadius:(NSString *)btnBorderRadius;
53+
- (void)setBtnTextColor:(NSString *)btnTextColor;
54+
- (void)setBtnBorderColor:(NSString *)btnBorderColor;
55+
- (void)setBtnBackgroundColor:(NSString *)btnBackgroundColor;
56+
- (void)setImageUrl:(NSString *)imageUrl;
57+
58+
/**
59+
If fallbackToSettings is YES and permission is denied, then we fallback to app’s notification settings.
60+
If fallbackToSettings is NO, then we just throw a log saying permission is denied.
61+
*/
62+
- (void)setFallbackToSettings:(BOOL)fallbackToSettings;
63+
64+
/**
65+
If skipAlert is YES, then we skip the settings alert dialog shown before opening app notification settings.
66+
*/
67+
- (void)setSkipSettingsAlert:(BOOL)skipAlert;
68+
69+
@end
70+
71+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)