Skip to content

Commit

Permalink
[feature][PUSH-32039] added methods to Pushwoosh Unity plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
akidison committed Jul 28, 2022
1 parent bf9cabf commit 8d4378d
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,18 @@ public void setUserId(String userId) {
PushwooshInApp.getInstance().setUserId(userId);
}

public void setUser(String userId, List<String> emails) {
Pushwoosh.getInstance().setUser(userId, emails);
}

public void setEmails(List<String> 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()) {
Expand Down
58 changes: 58 additions & 0 deletions PushwooshUnitySample/Assets/Plugins/iOS/UnityRuntime.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import <UserNotifications/UserNotifications.h>
#import <objc/runtime.h>
#import <Pushwoosh/PushNotificationManager.h>
#import <Pushwoosh/Pushwoosh.h>
#import <Pushwoosh/PWInAppManager.h>
#import <Pushwoosh/PWGDPRManager.h>
#import "PWMUserNotificationCenterDelegateProxy.h"
Expand Down Expand Up @@ -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];
Expand Down
15 changes: 15 additions & 0 deletions PushwooshUnitySample/Assets/Pushwoosh/PushNotificationsAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ public override void SetUserId(string userId)
pushwoosh.Call("setUserId", userId);
}

public override void SetUser(string userId, List<string> emails)
{
pushwoosh.Call("setUser", userId, emails);
}

public override void SetEmails(List<string> 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);
Expand Down
41 changes: 41 additions & 0 deletions PushwooshUnitySample/Assets/Pushwoosh/PushNotificationsIOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -143,6 +151,39 @@ public override void SetUserId(string userId)
pw_setUserId(userId);
}

public override void SetUser(string userId, List<string> emails)
{
List <string> stringEmails = new List<string>();

foreach (string email in emails) {
if (email != null)
stringEmails.Add(email);
}

string[] array = stringEmails.ToArray();

pw_setUser(userId, array);
}

public override void SetEmails(List<string> emails)
{
List <string> stringEmails = new List<string>();

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);
Expand Down
6 changes: 6 additions & 0 deletions PushwooshUnitySample/Assets/Scripts/PushNotificator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ void Start ()
}
Pushwoosh.Instance.SetUserId("%userId%");

Pushwoosh.Instance.SetUser("666777", new List<string> (new[] { "test1@test.com", "test2@test.com" }));

Pushwoosh.Instance.SetEmails(new List<string> (new[] { "test3@test.com", "test4@test.com" }));

Pushwoosh.Instance.SetEmail("test5@test.com");

Dictionary<string, object> attributes = new Dictionary<string, object>() {
{ "attribute", "value" },
};
Expand Down

0 comments on commit 8d4378d

Please sign in to comment.