123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- using UnityEngine;
- using System.Collections;
- using System.Runtime.InteropServices;
- using System.Collections.Generic;
- public class PushNotificationsIOS : Pushwoosh
- {
- #if UNITY_IPHONE && !UNITY_EDITOR
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_internalSendStringTags (string tagName, string[] tags);
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_initializePushManager(string appCode, string appName);
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_registerForRemoteNotifications();
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_unregisterForRemoteNotifications();
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_setListenerName(string listenerName);
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private System.IntPtr pw_getPushToken();
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private System.IntPtr pw_getPushwooshHWID();
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private System.IntPtr pw_getLaunchNotification();
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_clearLaunchNotification();
-
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_setIntTag(string tagName, int tagValue);
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_setStringTag(string tagName, string tagValue);
-
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_startLocationTracking();
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_stopLocationTracking();
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_clearNotificationCenter();
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_setBadgeNumber(int badge);
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_addBadgeNumber(int deltaBadge);
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_setUserId(string userId);
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_postEvent(string eventId, string attributes);
- [System.Runtime.InteropServices.DllImport("__Internal")]
- extern static private void pw_sendPurchase(string productId, double price, string currency);
- protected override void Initialize ()
- {
- pw_initializePushManager(Pushwoosh.ApplicationCode, Application.productName);
- pw_setListenerName(this.gameObject.name);
- }
- public override void RegisterForPushNotifications()
- {
- pw_registerForRemoteNotifications();
- }
- public override void UnregisterForPushNotifications()
- {
- pw_unregisterForRemoteNotifications();
- }
- public override string HWID
- {
- get { return Marshal.PtrToStringAnsi(pw_getPushwooshHWID()); }
- }
- public override string PushToken
- {
- get { return Marshal.PtrToStringAnsi(pw_getPushToken()); }
- }
- public string GetLaunchNotification()
- {
- return Marshal.PtrToStringAnsi(pw_getLaunchNotification());
- }
- public void ClearLaunchNotification()
- {
- pw_clearLaunchNotification();
- }
- public override void SetUserId(string userId)
- {
- pw_setUserId(userId);
- }
- protected override void PostEventInternal(string eventId, string attributes)
- {
- pw_postEvent(eventId, attributes);
- }
- public override void StartTrackingGeoPushes()
- {
- pw_startLocationTracking();
- }
- public override void StopTrackingGeoPushes()
- {
- pw_stopLocationTracking();
- }
- public override void SetListTag(string tagName, List<object> tagValues)
- {
- List <string> stringTags = new List<string>();
-
- foreach (object tagValue in tagValues) {
- string stringTag = tagValue.ToString();
-
- if (stringTag != null)
- stringTags.Add(stringTag);
- }
-
- string[] array = stringTags.ToArray();
-
- pw_internalSendStringTags (tagName, array);
- }
- public override void SetIntTag(string tagName, int tagValue)
- {
- pw_setIntTag(tagName, tagValue);
- }
-
- public override void SetStringTag(string tagName, string tagValue)
- {
- pw_setStringTag(tagName, tagValue);
- }
- public override void ClearNotificationCenter()
- {
- pw_clearNotificationCenter ();
- }
- public override void SetBadgeNumber(int number)
- {
- pw_setBadgeNumber (number);
- }
- public override void AddBadgeNumber(int deltaBadge)
- {
- pw_addBadgeNumber (deltaBadge);
- }
- public override void SendPurchase(string productId, double price, string currency)
- {
- pw_sendPurchase(productId, price, currency);
- }
- void onRegisteredForPushNotifications(string token)
- {
- RegisteredForPushNotifications (token);
- }
- void onFailedToRegisteredForPushNotifications(string error)
- {
- FailedToRegisteredForPushNotifications (error);
- }
- void onPushNotificationsReceived(string payload)
- {
- PushNotificationsReceived (payload);
- }
- #endif
- }
|