From 8d4378de8ba9887700ead1a21efd5fc055c23850 Mon Sep 17 00:00:00 2001 From: akiselev-pushwoosh Date: Thu, 28 Jul 2022 15:33:30 +0200 Subject: [PATCH] [feature][PUSH-32039] added methods to Pushwoosh Unity plugin --- .../pushwoosh/unityplugin/PushwooshProxy.java | 12 ++++ .../Assets/Plugins/iOS/UnityRuntime.m | 58 +++++++++++++++++++ .../Pushwoosh/PushNotificationsAndroid.cs | 15 +++++ .../Assets/Pushwoosh/PushNotificationsIOS.cs | 41 +++++++++++++ .../Assets/Scripts/PushNotificator.cs | 6 ++ 5 files changed, 132 insertions(+) diff --git a/PluginSource/Android/pushwoosh-unityplugin/src/main/java/com/pushwoosh/unityplugin/PushwooshProxy.java b/PluginSource/Android/pushwoosh-unityplugin/src/main/java/com/pushwoosh/unityplugin/PushwooshProxy.java index 1b20376..7b0e8e6 100644 --- a/PluginSource/Android/pushwoosh-unityplugin/src/main/java/com/pushwoosh/unityplugin/PushwooshProxy.java +++ b/PluginSource/Android/pushwoosh-unityplugin/src/main/java/com/pushwoosh/unityplugin/PushwooshProxy.java @@ -342,6 +342,18 @@ public void setUserId(String userId) { PushwooshInApp.getInstance().setUserId(userId); } + public void setUser(String userId, List emails) { + Pushwoosh.getInstance().setUser(userId, emails); + } + + public void setEmails(List emails) { + Pushwoosh.getInstance().setEmail(emails); + } + + public void setEmail(String email) { + Pushwoosh.getInstance().setEmail(email); + } + public void postEvent(String event, String attributesStr) { try { if (attributesStr.isEmpty()) { diff --git a/PushwooshUnitySample/Assets/Plugins/iOS/UnityRuntime.m b/PushwooshUnitySample/Assets/Plugins/iOS/UnityRuntime.m index 816e8f6..d91d590 100644 --- a/PushwooshUnitySample/Assets/Plugins/iOS/UnityRuntime.m +++ b/PushwooshUnitySample/Assets/Plugins/iOS/UnityRuntime.m @@ -7,6 +7,7 @@ #import #import #import +#import #import #import #import "PWMUserNotificationCenterDelegateProxy.h" @@ -69,6 +70,63 @@ void pw_setUserId(char *userId) { [[PWInAppManager sharedManager] setUserId:userIdStr]; } +void pw_setUser(char *userId, char **emails) { + size_t length = 0; + while (emails[length] != NULL) length++; + + NSMutableArray *emailsArray = [NSMutableArray array]; + NSString *userIdStr = [[NSString alloc] initWithUTF8String:userId]; + + for (int i = 0; i < length; i++) { + char *emailValue = emails[i]; + NSString *emailValueStr = [[NSString alloc] initWithUTF8String:emailValue]; + + if (emailValueStr) { + [emailsArray addObject:emailValueStr]; + } +#if !__has_feature(objc_arc) + [emailValueStr release]; +#endif + } + + if (emailsArray.count) { + [[Pushwoosh sharedInstance] setUser:userIdStr emails:emailsArray]; + } +#if !__has_feature(objc_arc) + [userIdStr release]; +#endif +} + +void pw_setEmails(char **emails) { + size_t length = 0; + while (emails[length] != NULL) length++; + + NSMutableArray *emailsArray = [NSMutableArray array]; + + for (int i = 0; i < length; i++) { + char *emailValue = emails[i]; + NSString *emailValueStr = [[NSString alloc] initWithUTF8String:emailValue]; + + if (emailValueStr) { + [emailsArray addObject:emailValueStr]; + } +#if !__has_feature(objc_arc) + [emailValueStr release]; +#endif + } + + if (emailsArray.count) { + [[Pushwoosh sharedInstance] setEmails:emailsArray]; + } +} + +void pw_setEmail(char *email) { + NSString *emailStr = [[NSString alloc] initWithUTF8String:email]; + + [[Pushwoosh sharedInstance] setEmail:emailStr]; +} + + void pw_postEvent(char *event, char *attributes) { NSString *eventStr = [[NSString alloc] initWithUTF8String:event]; NSString *attributesStr = [[NSString alloc] initWithUTF8String:attributes]; diff --git a/PushwooshUnitySample/Assets/Pushwoosh/PushNotificationsAndroid.cs b/PushwooshUnitySample/Assets/Pushwoosh/PushNotificationsAndroid.cs index 087768a..23fd181 100644 --- a/PushwooshUnitySample/Assets/Pushwoosh/PushNotificationsAndroid.cs +++ b/PushwooshUnitySample/Assets/Pushwoosh/PushNotificationsAndroid.cs @@ -121,6 +121,21 @@ public override void SetUserId(string userId) pushwoosh.Call("setUserId", userId); } + public override void SetUser(string userId, List emails) + { + pushwoosh.Call("setUser", userId, emails); + } + + public override void SetEmails(List emails) + { + pushwoosh.Call("setEmails", emails); + } + + public override void SetEmail(string email) + { + pushwoosh.Call("setEmail", email); + } + protected override void PostEventInternal(string eventId, string attributes) { pushwoosh.Call("postEvent", eventId, attributes); diff --git a/PushwooshUnitySample/Assets/Pushwoosh/PushNotificationsIOS.cs b/PushwooshUnitySample/Assets/Pushwoosh/PushNotificationsIOS.cs index d719fc0..024968d 100644 --- a/PushwooshUnitySample/Assets/Pushwoosh/PushNotificationsIOS.cs +++ b/PushwooshUnitySample/Assets/Pushwoosh/PushNotificationsIOS.cs @@ -65,6 +65,14 @@ public class PushNotificationsIOS : Pushwoosh [System.Runtime.InteropServices.DllImport("__Internal")] extern static private void pw_setUserId(string userId); + [System.Runtime.InteropServices.DllImport("__Internal")] + extern static private void pw_setUser(string userId, string[] emails); + + [System.Runtime.InteropServices.DllImport("__Internal")] + extern static private void pw_setEmails(string[] emails); + + [System.Runtime.InteropServices.DllImport("__Internal")] + extern static private void pw_setEmail(string email); [System.Runtime.InteropServices.DllImport("__Internal")] extern static private bool pw_gdprAvailable(); @@ -143,6 +151,39 @@ public override void SetUserId(string userId) pw_setUserId(userId); } + public override void SetUser(string userId, List emails) + { + List stringEmails = new List(); + + foreach (string email in emails) { + if (email != null) + stringEmails.Add(email); + } + + string[] array = stringEmails.ToArray(); + + pw_setUser(userId, array); + } + + public override void SetEmails(List emails) + { + List stringEmails = new List(); + + foreach (string email in emails) { + if (email != null) + stringEmails.Add(email); + } + + string[] array = stringEmails.ToArray(); + + pw_setEmails(array); + } + + public override void SetEmail(string email) + { + pw_setEmail(email); + } + protected override void PostEventInternal(string eventId, string attributes) { pw_postEvent(eventId, attributes); diff --git a/PushwooshUnitySample/Assets/Scripts/PushNotificator.cs b/PushwooshUnitySample/Assets/Scripts/PushNotificator.cs index eceff10..f9040ea 100644 --- a/PushwooshUnitySample/Assets/Scripts/PushNotificator.cs +++ b/PushwooshUnitySample/Assets/Scripts/PushNotificator.cs @@ -52,6 +52,12 @@ void Start () } Pushwoosh.Instance.SetUserId("%userId%"); + Pushwoosh.Instance.SetUser("666777", new List (new[] { "test1@test.com", "test2@test.com" })); + + Pushwoosh.Instance.SetEmails(new List (new[] { "test3@test.com", "test4@test.com" })); + + Pushwoosh.Instance.SetEmail("test5@test.com"); + Dictionary attributes = new Dictionary() { { "attribute", "value" }, };