Example #1
0
 public void iOSCancelAll()
 {
     foreach (var ntf in listNtfs)
     {
         NotificationServices.CancelLocalNotification(ntf);
     }
     listNtfs.Clear();
     setApplicationIconBadgeNumber(0);
 }
Example #2
0
 void OnAppPause(bool paused)
 {
     if (!paused)
     {
         foreach (var ntf in listNtfs)
         {
             NotificationServices.CancelLocalNotification(ntf);
         }
         listNtfs.Clear();
         setApplicationIconBadgeNumber(0);
     }
 }
Example #3
0
 internal bool DestroyNotification(PPNotification notification)
 {
     foreach (LocalNotification iOSNotification in NotificationServices.localNotifications)
     {
         if (notificationMatch(notification, iOSNotification))
         {
             NotificationServices.CancelLocalNotification(iOSNotification);
             return(true);
         }
     }
     return(false);
 }
Example #4
0
        public override void CancelNotification(int id)
        {
            if (!CheckInitialized())
            {
                return;
            }

            string idAsString = id.ToString();

            if (NotificationServices.localNotifications != null)
            {
                foreach (var notification in NotificationServices.localNotifications)
                {
                    if (notification.userInfo.Contains(m_idKeyName) && (string)notification.userInfo[m_idKeyName] == idAsString)
                    {
                        NotificationServices.CancelLocalNotification(notification);
                        return;
                    }
                }
            }

            if (NotificationServices.scheduledLocalNotifications != null)
            {
                foreach (var notification in NotificationServices.scheduledLocalNotifications)
                {
                    if (notification.userInfo.Contains(m_idKeyName) && (string)notification.userInfo[m_idKeyName] == idAsString)
                    {
                        NotificationServices.CancelLocalNotification(notification);
                        return;
                    }
                }
            }

            if (m_scheduledNotificationsWhenDisabled != null)
            {
                bool found = false;
                for (int i = m_scheduledNotificationsWhenDisabled.Count - 1; i >= 0; --i)
                {
                    var notification = m_scheduledNotificationsWhenDisabled[i];
                    if (notification.userData.ContainsKey(m_idKeyName) && notification.userData[m_idKeyName] == idAsString)
                    {
                        found = true;
                        m_scheduledNotificationsWhenDisabled.RemoveAt(i);
                    }
                }

                if (found)
                {
                    SaveScheduledNotificationsWhenDisabled();
                }
            }
        }
Example #5
0
        private void CleanupDuplications()
        {
            const float CHECK_INTERVAL = 1.1f;

            float time = UnityEngine.Time.unscaledTime;

            if (time - lastDuplicationCheck < CHECK_INTERVAL)
            {
                return;
            }
            lastDuplicationCheck = time;

            var dictionary = new Dictionary <int, List <LocalNotification> >();

            if (NotificationServices.scheduledLocalNotifications != null)
            {
                foreach (var notification in NotificationServices.scheduledLocalNotifications)
                {
                    int id = notification.userInfo != null?ExtractId(notification.userInfo) : -1;

                    if (dictionary.ContainsKey(id))
                    {
                        dictionary[id].Add(notification);
                    }
                    else
                    {
                        dictionary.Add(id, new List <LocalNotification> {
                            notification
                        });
                    }
                }
            }

            foreach (var entry in dictionary)
            {
                var list = entry.Value;
                if (list.Count > 1)
                {
                    UnityEngine.Debug.Log("UTNotifications: local notification duplication with id " + entry.Key + " detected. Cleaning up.");

                    // Sort by timestamps (newest first)
                    list.Sort((x, y) => ExtractTimestamp(y.userInfo).CompareTo(ExtractTimestamp(x.userInfo)));

                    // Remove outdated duplications
                    for (int i = 1; i < list.Count; ++i)
                    {
                        NotificationServices.CancelLocalNotification(list[i]);
                    }
                }
            }
        }
Example #6
0
    public void CancelScheduleLocalNotification(int type)
    {
#if UNITY_IPHONE
        foreach (var notif in NotificationServices.scheduledLocalNotifications)
        {
            if (notif.userInfo != null && notif.userInfo.Contains(userInfoKey_Type) && (int)notif.userInfo[userInfoKey_Type] == type)
            {
#if ENABLE_NOTIFICATION_LOG
                Debug.Log("[SysNotification] Cancel scheduled local Notification : " + Log(notif));
#endif

                NotificationServices.CancelLocalNotification(notif);

                return;
            }
        }
#endif
    }
Example #7
0
        private void HideNotification(LocalNotification notification)
        {
            if (notification.repeatInterval > CalendarUnit.Era)
            {
                LocalNotification replacementNotification = new LocalNotification();
                replacementNotification.applicationIconBadgeNumber = notification.applicationIconBadgeNumber;
                replacementNotification.alertAction    = notification.alertAction;
                replacementNotification.alertBody      = notification.alertBody;
                replacementNotification.repeatInterval = notification.repeatInterval;
                replacementNotification.hasAction      = notification.hasAction;
                replacementNotification.soundName      = notification.soundName;
                replacementNotification.userInfo       = notification.userInfo;
                replacementNotification.fireDate       = RepeatIntervalToDateTime(notification.repeatInterval);

                NotificationServices.ScheduleLocalNotification(replacementNotification);
            }

            NotificationServices.CancelLocalNotification(notification);
        }