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 tagValues) { List stringTags = new List(); 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 }