예제 #1
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
        }
예제 #2
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);
        }
예제 #3
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);
        }
        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);
        }
        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);
        }
예제 #6
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());
     }
 }
예제 #7
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);
        }
예제 #8
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);
        }