PushNotificationsIOS.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Runtime.InteropServices;
  4. using System.Collections.Generic;
  5. public class PushNotificationsIOS : Pushwoosh
  6. {
  7. #if UNITY_IPHONE && !UNITY_EDITOR
  8. [System.Runtime.InteropServices.DllImport("__Internal")]
  9. extern static private void pw_internalSendStringTags (string tagName, string[] tags);
  10. [System.Runtime.InteropServices.DllImport("__Internal")]
  11. extern static private void pw_initializePushManager(string appCode, string appName);
  12. [System.Runtime.InteropServices.DllImport("__Internal")]
  13. extern static private void pw_registerForRemoteNotifications();
  14. [System.Runtime.InteropServices.DllImport("__Internal")]
  15. extern static private void pw_unregisterForRemoteNotifications();
  16. [System.Runtime.InteropServices.DllImport("__Internal")]
  17. extern static private void pw_setListenerName(string listenerName);
  18. [System.Runtime.InteropServices.DllImport("__Internal")]
  19. extern static private System.IntPtr pw_getPushToken();
  20. [System.Runtime.InteropServices.DllImport("__Internal")]
  21. extern static private System.IntPtr pw_getPushwooshHWID();
  22. [System.Runtime.InteropServices.DllImport("__Internal")]
  23. extern static private System.IntPtr pw_getLaunchNotification();
  24. [System.Runtime.InteropServices.DllImport("__Internal")]
  25. extern static private void pw_clearLaunchNotification();
  26. [System.Runtime.InteropServices.DllImport("__Internal")]
  27. extern static private void pw_setIntTag(string tagName, int tagValue);
  28. [System.Runtime.InteropServices.DllImport("__Internal")]
  29. extern static private void pw_setStringTag(string tagName, string tagValue);
  30. [System.Runtime.InteropServices.DllImport("__Internal")]
  31. extern static private void pw_startLocationTracking();
  32. [System.Runtime.InteropServices.DllImport("__Internal")]
  33. extern static private void pw_stopLocationTracking();
  34. [System.Runtime.InteropServices.DllImport("__Internal")]
  35. extern static private void pw_clearNotificationCenter();
  36. [System.Runtime.InteropServices.DllImport("__Internal")]
  37. extern static private void pw_setBadgeNumber(int badge);
  38. [System.Runtime.InteropServices.DllImport("__Internal")]
  39. extern static private void pw_addBadgeNumber(int deltaBadge);
  40. [System.Runtime.InteropServices.DllImport("__Internal")]
  41. extern static private void pw_setUserId(string userId);
  42. [System.Runtime.InteropServices.DllImport("__Internal")]
  43. extern static private void pw_postEvent(string eventId, string attributes);
  44. [System.Runtime.InteropServices.DllImport("__Internal")]
  45. extern static private void pw_sendPurchase(string productId, double price, string currency);
  46. protected override void Initialize ()
  47. {
  48. pw_initializePushManager(Pushwoosh.ApplicationCode, Application.productName);
  49. pw_setListenerName(this.gameObject.name);
  50. }
  51. public override void RegisterForPushNotifications()
  52. {
  53. pw_registerForRemoteNotifications();
  54. }
  55. public override void UnregisterForPushNotifications()
  56. {
  57. pw_unregisterForRemoteNotifications();
  58. }
  59. public override string HWID
  60. {
  61. get { return Marshal.PtrToStringAnsi(pw_getPushwooshHWID()); }
  62. }
  63. public override string PushToken
  64. {
  65. get { return Marshal.PtrToStringAnsi(pw_getPushToken()); }
  66. }
  67. public string GetLaunchNotification()
  68. {
  69. return Marshal.PtrToStringAnsi(pw_getLaunchNotification());
  70. }
  71. public void ClearLaunchNotification()
  72. {
  73. pw_clearLaunchNotification();
  74. }
  75. public override void SetUserId(string userId)
  76. {
  77. pw_setUserId(userId);
  78. }
  79. protected override void PostEventInternal(string eventId, string attributes)
  80. {
  81. pw_postEvent(eventId, attributes);
  82. }
  83. public override void StartTrackingGeoPushes()
  84. {
  85. pw_startLocationTracking();
  86. }
  87. public override void StopTrackingGeoPushes()
  88. {
  89. pw_stopLocationTracking();
  90. }
  91. public override void SetListTag(string tagName, List<object> tagValues)
  92. {
  93. List <string> stringTags = new List<string>();
  94. foreach (object tagValue in tagValues) {
  95. string stringTag = tagValue.ToString();
  96. if (stringTag != null)
  97. stringTags.Add(stringTag);
  98. }
  99. string[] array = stringTags.ToArray();
  100. pw_internalSendStringTags (tagName, array);
  101. }
  102. public override void SetIntTag(string tagName, int tagValue)
  103. {
  104. pw_setIntTag(tagName, tagValue);
  105. }
  106. public override void SetStringTag(string tagName, string tagValue)
  107. {
  108. pw_setStringTag(tagName, tagValue);
  109. }
  110. public override void ClearNotificationCenter()
  111. {
  112. pw_clearNotificationCenter ();
  113. }
  114. public override void SetBadgeNumber(int number)
  115. {
  116. pw_setBadgeNumber (number);
  117. }
  118. public override void AddBadgeNumber(int deltaBadge)
  119. {
  120. pw_addBadgeNumber (deltaBadge);
  121. }
  122. public override void SendPurchase(string productId, double price, string currency)
  123. {
  124. pw_sendPurchase(productId, price, currency);
  125. }
  126. void onRegisteredForPushNotifications(string token)
  127. {
  128. RegisteredForPushNotifications (token);
  129. }
  130. void onFailedToRegisteredForPushNotifications(string error)
  131. {
  132. FailedToRegisteredForPushNotifications (error);
  133. }
  134. void onPushNotificationsReceived(string payload)
  135. {
  136. PushNotificationsReceived (payload);
  137. }
  138. #endif
  139. }