Ejemplo n.º 1
0
 /// <summary>
 /// Ask for permission to notify the user
 /// </summary>
 public void Initialize()
 {
     NotificationServices.RegisterForNotifications(
         NotificationType.Alert |
         NotificationType.Badge |
         NotificationType.Sound);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers a callback for push notifications.
        /// </summary>
        /// <param name="action"></param>
        private void RegisteriOSPushNotificationListener(Action <IDictionary <string, object> > action)
        {
            Dispatcher.Instance.Post(() => {
                // Check in every frame
                RegisteriOSPushNotificationListener(action);

                int remoteNotificationCount = NotificationServices.remoteNotificationCount;
                if (remoteNotificationCount == 0)
                {
                    return;
                }

                var remoteNotifications = NotificationServices.remoteNotifications;
                foreach (var val in remoteNotifications)
                {
                    var userInfo = val.userInfo;
                    var payload  = new Dictionary <string, object>();
                    foreach (var key in userInfo.Keys)
                    {
                        payload[key.ToString()] = userInfo[key];
                    }

                    // Finally, invoke the action for the remote notification payload.
                    action(payload);
                }

                NotificationServices.ClearRemoteNotifications();
            });
        }
Ejemplo n.º 3
0
        // Use this for initialization
        private void Start()
        {
            #if UNITY_IOS
            NotificationServices.RegisterForNotifications(NotificationType.Alert | NotificationType.Badge | NotificationType.Sound, false);
            #endif

            _mageFactory = new MageFactory(MageUpgradeManager.MagePrefabs, this);
            ElementController.Instance.TowerTextures  = TowerTextures;
            ElementController.Instance.ShrineTextures = ShrineTextures;
            ElementController.Instance.MageTextures   = MageTextures;
            ElementController.Instance.SpellParticles = SpellParticles;
            ElementController.Instance.ElementIcons   = ElementIcons;

            MageUpgradeManager.Init();

            if (PlayerPrefs.GetInt("sfxMute") == 1)
            {
                SFXSlider.AssignSlider();
                if (_audioManager && _audioManager.SFXAudio.mute)
                {
                    _audioManager.ToggleSound();
                }
                SFXSlider.ChangeValue();
            }

            if (PlayerPrefs.GetInt("musicMute") == 1)
            {
                MusicSlider.AssignSlider();
                if (_audioManager && _audioManager.MusicAudio.mute)
                {
                    _audioManager.ToggleMusic();
                }
                MusicSlider.ChangeValue();
            }

            //Currency Bonus
            if (!string.IsNullOrEmpty(PlayerPrefs.GetString("_currencyBonusEndTime")))
            {
                _currencyModifierEndTime = DateTime.Parse(PlayerPrefs.GetString("_currencyBonusEndTime"));
                if (_currencyModifierEndTime > DateTime.Now)
                {
                    var restTime = AdManager.BonusTime - (_currencyModifierEndTime - DateTime.Now).TotalSeconds;
                    _currencyModifier = PlayerPrefs.GetFloat("_currencyModifier");
                    UIManager.OpenCurrencyBonus(_currencyModifier);
                    AdManager.Timer.Cooldown((float)restTime, Time.time);
                }
            }
            //Damage Bonus
            if (!string.IsNullOrEmpty(PlayerPrefs.GetString("_damageBonusEndTime")))
            {
                _damageModifierEndTime = DateTime.Parse(PlayerPrefs.GetString("_damageBonusEndTime"));
                if (_damageModifierEndTime > DateTime.Now)
                {
                    var restTime = AdManager.BonusTime - (_damageModifierEndTime - DateTime.Now).TotalSeconds;
                    _damageModifier = PlayerPrefs.GetFloat("_damageModifier");
                    UIManager.OpenDamageBonus(_damageModifier);
                    AdManager.Timer.Cooldown((float)restTime, Time.time);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Register local notification and returns the ID. Used for quickly scheduling a notification.
        /// </summary>
        /// <param name="delayTime">Delay time.</param>
        /// <param name="message">Notification Message.</param>
        /// <param name="title">Notification Title.</param>
        /// <returns>ID of the registered notification.</returns>
        public int RegisterSimple(int delayTime, string message, string title = "")
        {
            // Needed a guaranteed unique ID
            int requestCode;

            for (int i = 0; i < MaxSimpleNotifications; i++)
            {
                requestCode = int.MaxValue - i;

                if (!NotificationExists(requestCode))
                {
                    LocalNotification notification = new LocalNotification();
                    notification.fireDate  = DateTime.Now.AddSeconds(delayTime);
                    notification.alertBody = message;
                    notification.userInfo  = new Dictionary <string, int>()
                    {
                        { NotificationID, requestCode }
                    };
                    NotificationServices.ScheduleLocalNotification(notification);
                    return(requestCode);
                }
            }

            Debug.LogError("[UniLocalNotification] - Exceeded maximum concurrent simple notifications!");
            return(-1);
        }
Ejemplo n.º 5
0
        void ScheduleNotification()
        {
#if UNITY_IOS
            var damageBonusTime = _damageModifierEndTime - DateTime.Now;
            var moneyBonusTime  = _currencyModifierEndTime - DateTime.Now;
            //schedule notification
            if (damageBonusTime.TotalSeconds > 0)
            {
                LocalNotification damageNotif = new LocalNotification();
                damageNotif.fireDate  = DateTime.Now.AddMinutes(damageBonusTime.Minutes);
                damageNotif.alertBody = "Your damage bonus has expired! Come and get another bonus!";
                NotificationServices.ScheduleLocalNotification(damageNotif);
            }
            if (moneyBonusTime.TotalSeconds > 0)
            {
                LocalNotification moneyNotif = new LocalNotification();
                moneyNotif.fireDate  = DateTime.Now.AddMinutes(moneyBonusTime.Minutes);
                moneyNotif.alertBody = "Your income bonus has expired! Come and get another bonus!";
                NotificationServices.ScheduleLocalNotification(moneyNotif);
            }
            // schedule notification to be delivered in 120 minutes
            LocalNotification notif = new LocalNotification();
            notif.fireDate  = DateTime.Now.AddMinutes(120);
            notif.alertBody = "The village is under attack! Defend it and gain loot!";
            NotificationServices.ScheduleLocalNotification(notif);

            // schedule notification to be delivered in 24 hours
            LocalNotification dayNotif = new LocalNotification();
            dayNotif.fireDate  = DateTime.Now.AddHours(24);
            dayNotif.alertBody = "Your mages earned a lot of gold! Come and upgrade them!";
            NotificationServices.ScheduleLocalNotification(dayNotif);
#endif
        }
Ejemplo n.º 6
0
 public virtual void Register(string id = "")
 {
     NotificationServices.RegisterForNotifications(
         NotificationType.Alert |
         NotificationType.Badge |
         NotificationType.Sound);
 }
Ejemplo n.º 7
0
        protected virtual void Update()
        {
            if (!tokenSent)
            {
                byte[] token = NotificationServices.deviceToken;
                if (token != null)
                {
                    hexToken = "%" + System.BitConverter.ToString(token).Replace('-', '%');
                    DevicePushIdReceived(hexToken);

                    tokenSent = true;
                }
            }

            if (NotificationServices.localNotificationCount > 0)
            {
                LocalNotificationReceived(NotificationServices.localNotifications [0].alertBody);
                NotificationServices.CancelLocalNotification(NotificationServices.localNotifications [0]);
                NotificationServices.ClearLocalNotifications();
            }

            if (NotificationServices.remoteNotificationCount > 0)
            {
                LocalNotificationReceived(NotificationServices.remoteNotifications [0].alertBody);
                NotificationServices.ClearRemoteNotifications();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Register local notification
        /// </summary>
        /// <param name="delayTime">Delay time.</param>
        /// <param name="message">Notification Message.</param>
        /// <param name="title">Notification Title.</param>
        public void Register(int delayTime, string message, string title = "")
        {
            LocalNotification notification = new LocalNotification();

            notification.fireDate  = System.DateTime.Now.AddSeconds(delayTime);
            notification.alertBody = message;
            NotificationServices.ScheduleLocalNotification(notification);
        }
Ejemplo n.º 9
0
        public override void ClearNotifications()
        {
            // Removing badge count
            NPBinding.Utility.SetApplicationIconBadgeNumber(0);

            // Clears notification
            NotificationServices.ClearLocalNotifications();
            NotificationServices.ClearRemoteNotifications();
        }
Ejemplo n.º 10
0
 void Start()
 {
     Debug.Log("NotificationExample: start");
     #if UNITY_IOS
     NotificationServices.RegisterForNotifications(
         NotificationType.Alert |
         NotificationType.Badge |
         NotificationType.Sound);
     StartCoroutine(CleanNotification());
     #endif
 }
        public void ScheduleDebug(RetentionNotification note)
        {
            var ln = new UnityEngine.iOS.LocalNotification
            {
                alertTitle = note.title,
                alertBody  = note.message,
                fireDate   = DateTime.Now.AddSeconds(15),
                applicationIconBadgeNumber = 1,
                repeatInterval             = CalendarUnit.Minute
            };

            NotificationServices.ScheduleLocalNotification(ln);
        }
Ejemplo n.º 12
0
        IEnumerator CleanNotification()
        {
            #if UNITY_IPHONE
            UnityEngine.iOS.LocalNotification l = new UnityEngine.iOS.LocalNotification();
            l.applicationIconBadgeNumber = -1;
            l.hasAction = false;
            NotificationServices.PresentLocalNotificationNow(l);
            yield return(new WaitForSeconds(0.2f));

            RearrageBradeNum();
            NotificationServices.ClearLocalNotifications();
            #endif
        }
        public void Schedule(DayOfWeek day, RetentionNotification note, DateTime date)
        {
            var ln = new UnityEngine.iOS.LocalNotification
            {
                alertTitle = note.title,
                alertBody  = note.message,
                fireDate   = date,
                applicationIconBadgeNumber = 1,
                repeatInterval             = CalendarUnit.Week
            };

            NotificationServices.ScheduleLocalNotification(ln);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Checks the Notifications for one that matches the ID and cancels it if it exists.
        /// </summary>
        /// <param name="requestCode">Notification ID.</param>
        private void InternalCancelNotification(int requestCode)
        {
            int index = 0;

            while (NotificationServices.GetLocalNotification(index) != null)
            {
                index++;
                LocalNotification notification = NotificationServices.GetLocalNotification(index);

                if (notification.userInfo.Contains(NotificationID) && (int)notification.userInfo[NotificationID] == requestCode)
                {
                    NotificationServices.CancelLocalNotification(notification);
                    break;
                }
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Register local notification with the specified ID.
 /// WARNING: You must track and manage these yourself, <see cref="CancelAllSimpleNotifications" /> cannot cancel notifications registerd in this fashion.
 /// </summary>
 /// <param name="requestCode">Notification ID. IDs 2,147,483,643 - 2,147,483,647 are reserved for simple notifications</param>
 /// <param name="delayTime">Delay time.</param>
 /// <param name="message">Notification Message.</param>
 /// <param name="title">Notification Title.</param>
 public void Register(int requestCode, int delayTime, string message, string title = "")
 {
     if (!NotificationExists(requestCode))
     {
         LocalNotification notification = new LocalNotification();
         notification.fireDate  = DateTime.Now.AddSeconds(delayTime);
         notification.alertBody = message;
         notification.userInfo  = new Dictionary <string, int>()
         {
             { NotificationID, requestCode }
         };
         NotificationServices.ScheduleLocalNotification(notification);
     }
     else
     {
         Debug.LogWarningFormat("[UniLocalNotification] - A notification with ID {0} is already registered. Cancel it before attemtping to reschedule it.", requestCode.ToString());
     }
 }
Ejemplo n.º 16
0
        void RearrageBradeNum()
        {
            int notificationCount = UnityEngine.iOS.NotificationServices.scheduledLocalNotifications.Length;
            List <UnityEngine.iOS.LocalNotification> notifications = new List <UnityEngine.iOS.LocalNotification>();

            for (int i = 0; i < notificationCount; i++)
            {
                var notification = UnityEngine.iOS.NotificationServices.scheduledLocalNotifications[i];
                notification.applicationIconBadgeNumber = i + 1;
                notifications.Add(notification);
            }
            NotificationServices.CancelAllLocalNotifications();

            for (int i = 0; i < notifications.Count; i++)
            {
                UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notifications[i]);
            }
        }
Ejemplo n.º 17
0
        public override void CancelLocalNotification(string _notificationID)
        {
            foreach (LocalNotification _scheduledNotification in NotificationServices.scheduledLocalNotifications)
            {
                IDictionary _scheduledNotificationUserInfo = _scheduledNotification.userInfo;

                if (_scheduledNotificationUserInfo != null)
                {
                    string _scheduledNotificationID = _scheduledNotificationUserInfo.GetIfAvailable <string>(CrossPlatformNotification.kNotificationID);

                    // Cancel notification
                    if (!string.IsNullOrEmpty(_scheduledNotificationID) && _scheduledNotificationID.Equals(_notificationID))
                    {
                        NotificationServices.CancelLocalNotification(_scheduledNotification);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public virtual void CancelLocalNotification(string id = "")
        {
            LocalNotification[] notifis = NotificationServices.scheduledLocalNotifications;
            if (notifis.Length > 0)
            {
                if (id == "")
                {
                    id = scheduleLocalNotification;
                }

                for (int i = 0; i < notifis.Length; i++)
                {
                    if (notifis [i].userInfo ["id"].ToString() == id)
                    {
                        NotificationServices.CancelLocalNotification(notifis [i]);
                    }
                }
            }
        }
Ejemplo n.º 19
0
        public virtual void ScheduleLocalNotification(DateTime date, string text, string id = "", string title = "")
        {
            CancelLocalNotification(id);

            LocalNotification notif = new LocalNotification();

            notif.fireDate  = date;
            notif.alertBody = text;

            if (id == "")
            {
                id = scheduleLocalNotification;
            }

            Dictionary <string, string> userInfo = new Dictionary <string, string> (1);

            userInfo ["id"] = id;
            notif.userInfo  = userInfo;
            NotificationServices.ScheduleLocalNotification(notif);
        }
Ejemplo n.º 20
0
        public override string ScheduleLocalNotification(CrossPlatformNotification _notification)
        {
            // Append notification id to user info
            string _notificationID = _notification.GenerateNotificationID();

            // Assign notification data
            LocalNotification _newNotification = new LocalNotification();

            _newNotification.alertBody      = _notification.AlertBody;
            _newNotification.fireDate       = _notification.FireDate;
            _newNotification.repeatInterval = iOSNotificationPayload.ConvertToCalendarUnit(_notification.RepeatInterval);
            _newNotification.userInfo       = _notification.UserInfo;

            // iOS Notification additional data
            CrossPlatformNotification.iOSSpecificProperties _iOSProperties = _notification.iOSProperties;

            if (_iOSProperties != null)
            {
                _newNotification.hasAction = _iOSProperties.HasAction;
                _newNotification.applicationIconBadgeNumber = _iOSProperties.BadgeCount;

                if (!string.IsNullOrEmpty(_iOSProperties.AlertAction))
                {
                    _newNotification.alertAction = _iOSProperties.AlertAction;
                }

                if (!string.IsNullOrEmpty(_iOSProperties.LaunchImage))
                {
                    _newNotification.alertLaunchImage = _iOSProperties.LaunchImage;
                }

                if (!string.IsNullOrEmpty(_iOSProperties.SoundName))
                {
                    _newNotification.soundName = _iOSProperties.SoundName;
                }
            }

            // Schedule notification
            NotificationServices.ScheduleLocalNotification(_newNotification);
            return(_notificationID);
        }
Ejemplo n.º 21
0
        void OnApplicationPause(bool pauseStatus)
        {
            if (Data == null)
            {
                return;
            }
            if (pauseStatus)
            {
                Time.timeScale = 0;
                #if UNITY_IOS
                NotificationServices.ClearLocalNotifications();
                NotificationServices.CancelAllLocalNotifications();
                ScheduleNotification();
                #endif

                PlayerPrefs.SetString("_gameCloseTime", System.DateTime.Now.ToString());
                Data.SetAchievementData(AchievementManager.GetAchievementKeeper());
                SaveLoadHelper.SaveGame(Data);
            }
            else
            {
                HandleDroppedMage();
                Time.timeScale = 1;
                #if UNITY_IOS
                //Debug.Log("Local notification count = " + NotificationServices.localNotificationCount);

                //if (NotificationServices.localNotificationCount > 0) {
                //    Debug.Log(NotificationServices.localNotifications[0].alertBody);
                //}

                // cancel all notifications first.
                NotificationServices.ClearLocalNotifications();
                NotificationServices.CancelAllLocalNotifications();
                #endif

                CalculateIdleIncomeAndShowNotification();
                StartCoroutine(WaveManager.SendWave());
            }
        }
Ejemplo n.º 22
0
 public override void CancelAllLocalNotification()
 {
     NotificationServices.CancelAllLocalNotifications();
 }
Ejemplo n.º 23
0
 public virtual void CancelAllLocalNotifications()
 {
     NotificationServices.CancelAllLocalNotifications();
 }