PushNotificationsWindows.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. #if (UNITY_WSA || UNITY_WSA_8_0 || UNITY_WSA_8_1 || UNITY_WSA_10_0) && !UNITY_EDITOR
  4. using PushwooshPlugin = PushwooshForWindows;
  5. #elif (UNITY_WP8 || UNITY_WP8_1) && !UNITY_EDITOR
  6. using PushwooshPlugin = PushwooshForWindowsPhone;
  7. #endif
  8. public class PushNotificationsWindows: Pushwoosh
  9. {
  10. #if (UNITY_WP8 || UNITY_WP8_1 || UNITY_WSA || UNITY_WSA_8_0 || UNITY_WSA_8_1 || UNITY_WSA_10_0) && !UNITY_EDITOR
  11. private PushwooshPlugin.Pushwoosh pushwoosh = null;
  12. void TokenReceived(object sender, PushwooshPlugin.TokenEventArgs events)
  13. {
  14. RegisteredForPushNotifications (events.Token);
  15. }
  16. void TokenError(object sender, PushwooshPlugin.TokenErrorEventArgs events)
  17. {
  18. FailedToRegisteredForPushNotifications (events.ErrorMessage);
  19. }
  20. void PushReceived(object sender, PushwooshPlugin.PushEventArgs events)
  21. {
  22. PushNotificationsReceived (events.PushPayload);
  23. }
  24. protected override void Initialize ()
  25. {
  26. pushwoosh = new PushwooshPlugin.Pushwoosh(Pushwoosh.ApplicationCode);
  27. pushwoosh.OnPushTokenReceived += TokenReceived;
  28. pushwoosh.OnPushTokenFailed += TokenError;
  29. pushwoosh.OnPushAccepted += PushReceived;
  30. }
  31. public override void RegisterForPushNotifications()
  32. {
  33. pushwoosh.SubscribeForPushNotifications ();
  34. }
  35. public override void UnregisterForPushNotifications()
  36. {
  37. pushwoosh.UnsubscribeForPushNotifications ();
  38. }
  39. public override string HWID
  40. {
  41. get { return pushwoosh.HWID; }
  42. }
  43. public override string PushToken
  44. {
  45. get { return pushwoosh.PushToken; }
  46. }
  47. public override void StartTrackingGeoPushes()
  48. {
  49. pushwoosh.StartGeoLocation();
  50. }
  51. public override void StopTrackingGeoPushes()
  52. {
  53. pushwoosh.StopGeoLocation();
  54. }
  55. public override void SetIntTag(string tagName, int tagValue)
  56. {
  57. var tags = new List<KeyValuePair<string, object>>();
  58. tags.Add (new KeyValuePair<string, object>(tagName, tagValue));
  59. pushwoosh.SetTags (tags);
  60. }
  61. public override void SetStringTag(string tagName, string tagValue)
  62. {
  63. var tags = new List<KeyValuePair<string, object>>();
  64. tags.Add (new KeyValuePair<string, object>(tagName, tagValue));
  65. pushwoosh.SetTags (tags);
  66. }
  67. public override void SetListTag(string tagName, List<object> tagValues)
  68. {
  69. var tags = new List<KeyValuePair<string, object>>();
  70. tags.Add (new KeyValuePair<string, object>(tagName, tagValues));
  71. pushwoosh.SetTags (tags);
  72. }
  73. #endif
  74. }