Esempio n. 1
0
        public static void cancelNotifyByMsg(string msg)
        {
            if (string.IsNullOrEmpty(msg))
            {
                return;
            }
#if UNITY_IOS
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                UnityEngine.iOS.LocalNotification[] lns  = UnityEngine.iOS.NotificationServices.localNotifications;
                UnityEngine.iOS.LocalNotification   cell = null;
                for (int i = 0; i < lns.Length; i++)
                {
                    cell = lns [i];
                    if (cell.alertBody.Equals(msg))
                    {
                        UnityEngine.iOS.NotificationServices.CancelLocalNotification(cell);
                        return;
                    }
                }
            }
#elif UNITY_ANDROID && !UNITY_EDITOR
            if (Application.platform == RuntimePlatform.Android)
            {
                jpushClass.CallStatic("cancelNotification", msg);
            }
#endif
        }
Esempio n. 2
0
 public void NotificationMessage(string message, System.DateTime newDate, bool isRepeatDay)
 {
     if (!m_isPushToggleOn)
     {
         return;
     }
     //推送时间需要大于当前时间
     if (newDate > System.DateTime.Now)
     {
         UnityEngine.iOS.LocalNotification localNotification = new UnityEngine.iOS.LocalNotification();
         localNotification.fireDate  = newDate;
         localNotification.alertBody = message;
         localNotification.applicationIconBadgeNumber = 1;
         localNotification.hasAction = true;
         if (isRepeatDay)
         {
             //是否每天定期循环
             localNotification.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ChineseCalendar; //中国日历
             localNotification.repeatInterval = UnityEngine.iOS.CalendarUnit.Day;                   //每日推送
         }
         localNotification.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName;
         UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Sound);
         //以特定的类型推送
         UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(localNotification);
     }
 }
Esempio n. 3
0
        private void ScheduleLocalNotification(string title, string message, System.DateTime date, bool repeatPerDay)
        {
            if (date < System.DateTime.Now)
            {
                EB.Debug.LogWarning("ScheduleLocalNotification: too late to schedule notification");
                return;
            }

            //EB.Debug.Log("NotificationMessage: start NotificationMessage message = {0} date = {1} repeat = {2}", message, date, repeatPerDay);

#if UNITY_EDITOR
            //EB.Debug.Log("ScheduleLocalNotification: not support in editor");
#elif UNITY_IPHONE
            UnityEngine.iOS.LocalNotification localNotification = new UnityEngine.iOS.LocalNotification();
            localNotification.fireDate  = date;
            localNotification.alertBody = message;
            localNotification.applicationIconBadgeNumber = 1;
            localNotification.hasAction = false;
            if (repeatPerDay)
            {
                localNotification.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ChineseCalendar;
                localNotification.repeatInterval = UnityEngine.iOS.CalendarUnit.Day;
            }
            localNotification.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName;
            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(localNotification);
#elif UNITY_ANDROID
            using (AndroidJavaClass jc = new AndroidJavaClass("org.manhuang.android.NotificationManager"))
            {
                var             utcDate    = date.ToUniversalTime();
                System.DateTime Jan1St1970 = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
                long            millis     = (long)((utcDate - Jan1St1970).TotalMilliseconds);
                jc.CallStatic("scheduleLocalNotification", title, message, millis, repeatPerDay ? 1 : 0);
            }
#endif
        }
Esempio n. 4
0
        /// <summary>
        /// Schedules a notification to inform the player on lives replenished.
        /// </summary>
        private void scheduleNotification()
        {
            double secondsDelay = 0D;

                        #if UNITY_IOS || UNITY_ANDROID
            clearNotification();
            if (!HasMaxLives)
            {
                if (string.IsNullOrEmpty(LocalNotificationSettings.AlertBody))
                {
                    Debug.LogError("Could not schedule local notification because the AlertBody property has not been set.");
                    return;
                }
                Debug.Log("Scheduling local notification...");
                secondsDelay = secondsToNextLife + ((MaxLives - lives - 1) * (MinutesToRecover * 60));
            }
                        #endif

                        #if UNITY_IOS
            if (!HasMaxLives)
            {
                var notification = new UnityEngine.iOS.LocalNotification();
                //notification.fireDate = DateTime.Now.AddSeconds(secondsDelay);
                notification.fireDate = UnbiasedTime.Instance.Now().AddSeconds(secondsDelay);
                if (!string.IsNullOrEmpty(LocalNotificationSettings.AlertAction.Trim()))
                {
                    notification.alertAction = LocalNotificationSettings.AlertAction.Trim();
                }
                notification.alertBody = LocalNotificationSettings.AlertBody;
                notification.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName;

                var options = new Dictionary <string, string>();
                options.Add(LOCAL_NOTIF_KEY, "");
                notification.userInfo = options;
                UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification);
            }
                        #endif
                        #if UNITY_ANDROID && ANDROID_NOTIFICATIONS
            if (Lives == 0)
            {
                PlayerPrefs.SetInt(LOCAL_NOTIF_KEY,
                                   NotificationManager.SendWithAppIcon(
                                       TimeSpan.FromSeconds(SecondsToNextLife),
                                       Application.productName,
                                       LocalNotificationSettings.AlertBody2,
                                       new Color(0, 0.6f, 1),
                                       NotificationIcon.Star));
            }
            else
            {
                PlayerPrefs.SetInt(LOCAL_NOTIF_KEY,
                                   NotificationManager.SendWithAppIcon(
                                       TimeSpan.FromSeconds(secondsDelay),
                                       Application.productName,
                                       LocalNotificationSettings.AlertBody,
                                       new Color(0, 0.6f, 1),
                                       NotificationIcon.Star));
            }
                        #endif
        }
Esempio 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
        }
Esempio n. 6
0
        /// <summary>
        /// Clears the LivesManager local notification if previously set.
        /// </summary>
        private void clearNotification()
        {
                        #if UNITY_IOS
            UnityEngine.iOS.LocalNotification notifToCancel = null;
            var localNotifications = UnityEngine.iOS.NotificationServices.scheduledLocalNotifications;

            try {
                for (int i = 0; i < localNotifications.Length; i++)
                {
                    if (localNotifications[i].userInfo != null && localNotifications[i].userInfo.Count > 0 && localNotifications[i].userInfo.Contains(LOCAL_NOTIF_KEY))
                    {
                        notifToCancel = localNotifications[i];
                        break;
                    }
                }
            } finally {
                if (notifToCancel != null)
                {
                    UnityEngine.iOS.NotificationServices.CancelLocalNotification(notifToCancel);
                }
            }
                        #endif
                        #if UNITY_ANDROID && ANDROID_NOTIFICATIONS
            if (PlayerPrefs.HasKey(LOCAL_NOTIF_KEY))
            {
                NotificationManager.Cancel(PlayerPrefs.GetInt(LOCAL_NOTIF_KEY));
            }
                        #endif
        }
		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;
		}
Esempio n. 8
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);
        }
Esempio n. 9
0
        /// <summary>
        /// Schedule customizable notification.
        /// </summary>
        public static int SendCustom(NotificationParams notificationParams)
        {
            #if UNITY_EDITOR
            Debug.LogWarning("Simple Android Notifications are not supported for current platform. Build and play this scene on android device!");
            #elif UNITY_ANDROID
            var p              = notificationParams;
            var delay          = (long)p.Delay.TotalMilliseconds;
            var repeatInterval = p.Repeat ? (long)p.RepeatInterval.TotalMilliseconds : 0;
            var vibration      = string.Join(",", p.Vibration.Select(i => i.ToString()).ToArray());

            new AndroidJavaClass(FullClassName).CallStatic("SetNotification", p.Id, p.GroupName ?? "", p.GroupSummary ?? "", p.ChannelId, p.ChannelName, delay, Convert.ToInt32(p.Repeat), repeatInterval, p.Title, p.Message, p.Ticker, Convert.ToInt32(p.Multiline),
                                                           Convert.ToInt32(p.Sound), p.CustomSound ?? "", Convert.ToInt32(p.Vibrate), vibration, Convert.ToInt32(p.Light), p.LightOnMs, p.LightOffMs, ColotToInt(p.LightColor), p.LargeIcon ?? "", GetSmallIconName(p.SmallIcon), ColotToInt(p.SmallIconColor), (int)p.ExecuteMode, p.CallbackData, MainActivityClassName);

            NotificationIdHandler.AddScheduledNotificaion(p.Id);
            #elif UNITY_IPHONE
            var notification = new UnityEngine.iOS.LocalNotification
            {
                hasAction = false,
                alertBody = notificationParams.Message,
                fireDate  = DateTime.Now.Add(notificationParams.Delay)
            };

            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification);
            #endif

            return(notificationParams.Id);
        }
Esempio n. 10
0
        //本地推送 你可以传入一个固定的推送时间
        public override void AddNotificationMessage(string title, string message, System.DateTime newDate, string loopType, int badgeNum)
        {
            //推送时间需要大于当前时间
            if (newDate > System.DateTime.Now)
            {
                UnityEngine.iOS.NotificationType notifiType = new UnityEngine.iOS.NotificationType();
                notifiType = UnityEngine.iOS.NotificationType.Alert;
                notifiType = UnityEngine.iOS.NotificationType.Badge;
                notifiType = UnityEngine.iOS.NotificationType.Sound;
                UnityEngine.iOS.NotificationServices.RegisterForNotifications(notifiType);


                UnityEngine.iOS.LocalNotification localNotification = new UnityEngine.iOS.LocalNotification();
                localNotification.fireDate    = newDate;
                localNotification.alertBody   = message;
                localNotification.alertAction = title;
                localNotification.applicationIconBadgeNumber = 1;
                localNotification.hasAction = true;
                if (loopType == "day")
                {
                    //是否每天定期循环
                    localNotification.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ChineseCalendar;
                    localNotification.repeatInterval = UnityEngine.iOS.CalendarUnit.Day;
                }
                else if (loopType == "week")
                {
                    //是否每周定期循环
                    localNotification.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ChineseCalendar;
                    localNotification.repeatInterval = UnityEngine.iOS.CalendarUnit.Week;
                }
                localNotification.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName;
                UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(localNotification);
            }
        }
Esempio n. 11
0
 // 清除推送消息
 void CleanNotification()
 {
     UnityEngine.iOS.LocalNotification ln = new UnityEngine.iOS.LocalNotification();
     ln.applicationIconBadgeNumber = -1;
     UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(ln);
     UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications();
     UnityEngine.iOS.NotificationServices.ClearLocalNotifications();
 }
Esempio n. 12
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);
        }
Esempio n. 13
0
 //清空所有本地消息
 public override void CleanNotification()
 {
     UnityEngine.iOS.LocalNotification loc = new UnityEngine.iOS.LocalNotification();
     loc.applicationIconBadgeNumber = -1;
     UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(loc);
     UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications();
     UnityEngine.iOS.NotificationServices.ClearLocalNotifications();
 }
Esempio n. 14
0
        private void CreateLocalNotification(string aMessage, DateTime aTime)
        {
#if !UNITY_EDITOR && UNITY_IOS
            UnityEngine.iOS.LocalNotification shortNotification = new UnityEngine.iOS.LocalNotification();
            shortNotification.fireDate  = aTime;
            shortNotification.alertBody = aMessage;
            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(shortNotification);
#endif
        }
Esempio n. 15
0
        public void CleanNotification()
        {
#if UNITY_IPHONE
            UnityEngine.iOS.LocalNotification l = new UnityEngine.iOS.LocalNotification();
            l.applicationIconBadgeNumber = -1;
            UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(l);
            UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications();
            UnityEngine.iOS.NotificationServices.ClearLocalNotifications();
#endif
        }
Esempio n. 16
0
        void ScheduleNotificationIOS(string title, string content, DateTime dateTime,
                                     bool hasAction = false, bool hasSound = false, bool hasVibrate = false)
        {
            UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification();

            notif.alertAction = title;
            notif.alertBody   = content;
            notif.fireDate    = dateTime;
            notif.hasAction   = hasAction;

            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notif);
        }
        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);
        }
Esempio n. 18
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);
        }
Esempio n. 20
0
        public static void ScheduleAlert(string body, string action, long fireTime)
        {
            var localDate = UTCSecondstoLocalTime(fireTime);

#if UNITY_IOS
            UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification();
            notif.alertBody      = body;
            notif.alertAction    = action;
            notif.fireDate       = localDate;
            notif.repeatInterval = UnityEngine.iOS.CalendarUnit.Day;
            Debug.Log(string.Format("ScheduleAlert date={0} body={1} action={2} interval={3}", localDate.ToString(), body, action, notif.repeatInterval.ToString()));
            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notif);
#endif
        }
 void Cotc_GotDomainLoopEvent(DomainEventLoop sender, EventLoopArgs args)
 {
     // When we receive a message, it means that the pending notification has been approved, so reset the application badge
     #if UNITY_IPHONE
     if (args.Message.Has("osn")) {
         Debug.LogWarning ("Will clear events");
         UnityEngine.iOS.NotificationServices.ClearRemoteNotifications();
         var setCountNotif = new UnityEngine.iOS.LocalNotification();
         setCountNotif.fireDate = System.DateTime.Now;
         setCountNotif.applicationIconBadgeNumber = -1;
         setCountNotif.hasAction = false;
         UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(setCountNotif);
     }
     #endif
 }
Esempio n. 22
0
        public ILocalGameNotifiation Schedule(string title, string body, string image, System.DateTime time)
        {
            UnityEngine.iOS.LocalNotification localNotification = new UnityEngine.iOS.LocalNotification()
            {
                alertAction      = title,
                alertBody        = body,
                fireDate         = time,
                alertLaunchImage = image
            };
            Notification notification = new Notification(localNotification);

            _notifications[localNotification] = notification;
            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(localNotification);

            return(notification);
        }
        public void ClearAll()
        {
            // 取消所有的本地通知
            UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications();

            // 清除本地通知
            UnityEngine.iOS.NotificationServices.ClearLocalNotifications();

            // 清除角标
            UnityEngine.iOS.LocalNotification notification = new UnityEngine.iOS.LocalNotification();
            notification.applicationIconBadgeNumber = -1;
            notification.hasAction = false;
            notification.fireDate  = System.DateTime.Now.AddSeconds(DELAY_PUSH_SECONDS);
            notification.alertBody = "";
            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification);
        }
        void Cotc_GotDomainLoopEvent(DomainEventLoop sender, EventLoopArgs args)
        {
            // When we receive a message, it means that the pending notification has been approved, so reset the application badge
#if UNITY_IPHONE
            if (args.Message.Has("osn"))
            {
                Debug.LogWarning("Will clear events");
                UnityEngine.iOS.NotificationServices.ClearRemoteNotifications();
                var setCountNotif = new UnityEngine.iOS.LocalNotification();
                setCountNotif.fireDate = System.DateTime.Now;
                setCountNotif.applicationIconBadgeNumber = -1;
                setCountNotif.hasAction = false;
                UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(setCountNotif);
            }
#endif
        }
Esempio n. 25
0
        /// <summary>
        /// 通知を設定
        /// </summary>
        /// <param name="id">通知ID(Androidのみ。同IDは上書きされる)</param>
        /// <param name="tickerText">通知時のテキスト(Androidのみ)</param>
        /// <param name="contentTitle">通知バーに表示されるタイトル</param>
        /// <param name="contentText">通知バーに表示されるテキスト</param>
        /// <param name="fireTime">通知する時間(Unix Time)</param>
        public static void Schedule(int id, string tickerText, string contentTitle, string contentText, ulong fireTime, int badgeNumber = 0)
        {
#if !UNITY_EDITOR
#if UNITY_ANDROID
            AndroidObj.Call("ScheduleNotification", id, tickerText, contentTitle, contentText, (long)fireTime);
#elif UNITY_IPHONE
            var no = new UnityEngine.iOS.LocalNotification();
            no.alertAction = contentTitle;
            no.alertBody   = contentText;
            no.fireDate    = CSSystem.UnixEpoch.AddSeconds(fireTime);
            no.soundName   = UnityEngine.iOS.LocalNotification.defaultSoundName;
            no.applicationIconBadgeNumber = badgeNumber;
            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(no);
#endif
#endif
        }
Esempio n. 26
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;
                }
            }
        }
        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 = SCHEDULE_LOCAL_NOTIFICATION;
            }

            Dictionary<string, string> userInfo = new Dictionary<string, string> (1);
            userInfo ["id"] = id;
            notif.userInfo = userInfo;
            NotificationServices.ScheduleLocalNotification (notif);
        }
Esempio n. 28
0
 //本地推送 你可以传入一个固定的推送时间
 public static void NotificationMessage(string message, System.DateTime newDate, bool isRepeatDay)
 {
     UnityEngine.iOS.LocalNotification localNotification = new UnityEngine.iOS.LocalNotification();
     localNotification.fireDate  = newDate;
     localNotification.alertBody = message;
     localNotification.applicationIconBadgeNumber = 1;
     localNotification.hasAction = true;
     if (isRepeatDay)
     {
         //是否每天定期循环
         localNotification.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ChineseCalendar;
         localNotification.repeatInterval = UnityEngine.iOS.CalendarUnit.Day;
     }
     localNotification.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName;
     UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Sound);
     UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(localNotification);
 }
Esempio n. 29
0
 void ScheduleNotificationForiOSWithMessage(string text, System.DateTime fireDate)
 {
     if (Application.platform == RuntimePlatform.IPhonePlayer)
     {
         Debug.Log("remoteNotificationCount: " + UnityEngine.iOS.NotificationServices.remoteNotificationCount);
         Debug.Log("localNotificationCount: " + UnityEngine.iOS.NotificationServices.localNotificationCount);
         Debug.Log("scheduledLocalNotifications: " + UnityEngine.iOS.NotificationServices.scheduledLocalNotifications.Length);
         UnityEngine.iOS.LocalNotification notification = new UnityEngine.iOS.LocalNotification();
         notification.fireDate    = fireDate;
         notification.alertAction = "Alert";
         notification.alertBody   = text;
         notification.hasAction   = false;
         notification.applicationIconBadgeNumber = UnityEngine.iOS.NotificationServices.scheduledLocalNotifications.Length + 1;
         notification.userInfo.Add("id", UnityEngine.Random.Range(0, int.MaxValue));
         UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification);
     }
 }
Esempio n. 30
0
        public void NotificationMessage(string title, string message, System.DateTime newDate)
        {
#if UNITY_IPHONE
            //推送时间需要大于当前时间
            if (newDate > System.DateTime.Now)
            {
                UnityEngine.iOS.LocalNotification localNotification = new UnityEngine.iOS.LocalNotification();
                localNotification.fireDate  = newDate;
                localNotification.alertBody = message;
                localNotification.applicationIconBadgeNumber = 1;
                localNotification.hasAction   = true;
                localNotification.alertAction = title;
                localNotification.soundName   = UnityEngine.iOS.LocalNotification.defaultSoundName;
                UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(localNotification);
            }
#endif
        }
Esempio n. 31
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());
     }
 }
Esempio n. 32
0
        public int ScheduleNotification(NotificationParams notificationParams)
        {
            var p            = notificationParams;
            var delaySeconds = (int)p.Delay.TotalSeconds;
            var delayMs      = (long)p.Delay.TotalMilliseconds;

            UnityEngine.iOS.LocalNotification notification = new UnityEngine.iOS.LocalNotification();
            DateTime now      = DateTime.Now;
            DateTime fireDate = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second).AddSeconds(delaySeconds);

            notification.fireDate    = fireDate;
            notification.alertBody   = p.Message;
            notification.alertAction = p.Title;
            notification.hasAction   = false;
            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification);

            return((int)fireDate.Ticks);
        }
        /// <summary>
        /// Schedule customizable notification.
        /// </summary>
        public static int SendPushCustom(NotificationParams notificationParams)
        {
            #if UNITY_ANDROID && !UNITY_EDITOR
            UserEditor.Getsingleton.EditLog("START AOS LOCAL PUSH");

            var p     = notificationParams;
            var delay = (long)p.Delay.TotalMilliseconds;
            NotificationManager.id = p.Id;

            new AndroidJavaClass(FullClassName).CallStatic("SetNotification", p.Id, delay, p.Title, p.Message, p.Ticker,
                                                           p.Sound ? 1 : 0, p.Vibrate ? 1 : 0, p.Light ? 1 : 0, p.LargeIcon, GetSmallIconName(p.SmallIcon), ColotToInt(p.SmallIconColor), MainActivityClassName);
#elif UNITY_IOS
            //Init_Notification();
            UserEditor.Getsingleton.EditLog("START IOS LOCAL PUSH");

            UnityEngine.iOS.LocalNotification noti = new UnityEngine.iOS.LocalNotification();
            noti.alertAction = notificationParams.Title;
            noti.alertBody   = notificationParams.Message;
            noti.applicationIconBadgeNumber = 0;

            IDictionary userInfo = new Dictionary <string, int>(1);
            userInfo["id"] = notificationParams.Id;
            noti.userInfo  = userInfo;

            noti.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName;
            UserEditor.Getsingleton.EditLog("now : " + TimeManager.Instance.Get_nowTime());
            UserEditor.Getsingleton.EditLog("notificationParams.Delay : " + notificationParams.Delay);

            DateTime addingTime = DateTime.Now.Add(notificationParams.Delay);

            UserEditor.Getsingleton.EditLog("adding : " + addingTime);

            //DateTime a = new DateTime(addingTime.Year,addingTime.Month,addingTime.Hour,addingTime.Minute,addingTime.Second);
            noti.fireDate = DateTime.Now;
            UserEditor.Getsingleton.EditLog("noti.fireDate11 : " + noti.fireDate);
            noti.fireDate = noti.fireDate.Add(notificationParams.Delay);
            UserEditor.Getsingleton.EditLog("noti.fireDate22: " + noti.fireDate);
            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(noti);
#else
            Debug.LogWarning("Simple Android Notifications are not supported for current platform. Build and play this scene on android device!");
            #endif

            return(notificationParams.Id);
        }