//本地推送 你可以传入一个固定的推送时间
    public static void NotificationMessage(string message, System.DateTime newDate, bool isRepeat)
    {
#if UNITY_IPHONE
        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            //推送时间需要大于当前时间
            if (newDate > System.DateTime.Now)
            {
                LocalNotification localNotification = new LocalNotification();
                localNotification.fireDate  = newDate;
                localNotification.alertBody = message;
                localNotification.applicationIconBadgeNumber = 1;
                localNotification.hasAction = true;
                if (isRepeat)
                {
                    localNotification.repeatCalendar = CalendarIdentifier.ChineseCalendar;
                    // Repeat per week
                    localNotification.repeatInterval = CalendarUnit.Week;
                }
                localNotification.soundName = LocalNotification.defaultSoundName;
                NotificationServices.ScheduleLocalNotification(localNotification);
            }
        }
#endif
    }
Esempio n. 2
0
        public override void ResetBadgeNumber()
        {
            LocalNotification ntf = new LocalNotification();

            ntf.fireDate = DateTime.Now.AddSeconds(1);
            ntf.applicationIconBadgeNumber = -1;
            NotificationServices.ScheduleLocalNotification(ntf);
        }
Esempio n. 3
0
    public void SetScheduleNotification()
    {
        for (int i = 0; i < scheduleNotifications.Count; i++)
        {
            NotificationServices.ScheduleLocalNotification(scheduleNotifications[i]);
        }

        scheduleNotifications.Clear();
    }
Esempio n. 4
0
        public override void ScheduleNotification(DateTime dateTime, string title, string body)
        {
            SimpleNotifier_Register();

            LocalNotification notification = new LocalNotification();

            notification.fireDate    = dateTime;
            notification.alertAction = title;
            notification.alertBody   = body;

            NotificationServices.ScheduleLocalNotification(notification);
        }
Esempio n. 5
0
    public void ScheduleLocalNotification(System.DateTime dateTime, string message, int appBadgeNumber, bool hasAction, string actionTitle, int type, int id, int repeatInterval)
    {
#if UNITY_IPHONE
        // Skip notification between 23h~9h
        int timeHour = dateTime.Hour;
        if (timeHour >= 23 || timeHour <= 9)
        {
            Debug.Log("Skip notification : " + dateTime);
            return;
        }

        // Skip disabled notification

        var notif = new LocalNotification();
        notif.fireDate  = dateTime;
        notif.alertBody = ConfigDatabase.DefaultCfg.StringsConfig.GetString("Notification", message);
        notif.applicationIconBadgeNumber = appBadgeNumber;
        notif.hasAction      = hasAction;
        notif.alertAction    = ConfigDatabase.DefaultCfg.StringsConfig.GetString("Notification", actionTitle);
        notif.repeatInterval = GameUtility.TimeDurationType2CalendarUnit(repeatInterval);

        // Set userInfo by Local.
        var userInfo = new Dictionary <string, int>();
        userInfo.Add(userInfoKey_Type, type);
        userInfo.Add(userInfoKey_ID, id);
        notif.userInfo = userInfo;

        // There is some problem in editor, the userinfo is null after set value, it's ok on IOS device
        if (notif.userInfo != null)
        {
#if ENABLE_NOTIFICATION_LOG
            Debug.Log(string.Format("[SysNotification] Local Notification Scheduled : {0},{1},{2}", type, id, Log(notif)));
#endif

#if !DISABLE_LOCAL_NOTIFICATION
            NotificationServices.ScheduleLocalNotification(notif);
#endif
        }
        else
        {
#if !UNITY_EDITOR // Disable log for editor
            Debug.LogError("[SysNotification] userInfo is null");
#endif
        }
#endif
    }
        protected void ScheduleLocalNotification(string pAlertBody, DateTime pFireDate, CalendarUnit pUnit)
        {
            LocalNotification localNotification = new LocalNotification();

            localNotification.fireDate  = pFireDate;
            localNotification.alertBody = pAlertBody;
            localNotification.applicationIconBadgeNumber = 1;
            localNotification.hasAction      = true;
            localNotification.repeatCalendar = CalendarIdentifier.GregorianCalendar;
            localNotification.repeatInterval = pUnit;
            NotificationServices.ScheduleLocalNotification(localNotification);

            if (IsTestMode)
            {
                UnityEngine.Debug.LogErrorFormat("{0}->ScheduleLocalNotification: pAlertBody: {1}], pFireDate: {2}, pUnit: {3}", GetType().Name, pAlertBody, pFireDate, pUnit);
            }
        }
Esempio n. 7
0
    private static void ResetAllEvents()
    {
        List <LocalNotificationDesc> sortedAllEvents = GetSortedEvents();

        for (int i = 0; i < sortedAllEvents.Count; ++i)
        {
            LocalNotification ln = new LocalNotification();
            ln.fireDate = sortedAllEvents[i].fireDate;

            ln.alertBody = sortedAllEvents[i].message;
            ln.applicationIconBadgeNumber = i + 1;
            ln.soundName = LocalNotification.defaultSoundName;

            Debug.Log("Schedule notification: " + i.ToString() + " event messsage " + sortedAllEvents[i].message + " , date " + sortedAllEvents[i].fireDate.ToString());

            NotificationServices.ScheduleLocalNotification(ln);
        }
    }
    public static void ScheduleLocalNotification(int id, DateTime time, string titleOnAndroid, string actionName,
                                                 string message, bool repeatEveryday = false)
    {
        var notif = new LocalNotification
        {
            alertAction = actionName,
            alertBody   = message,
            applicationIconBadgeNumber = 1,
            fireDate  = time.ToUniversalTime(),
            hasAction = true
        };

        if (repeatEveryday)
        {
            notif.repeatInterval = CalendarUnit.Day;
        }
        NotificationServices.ScheduleLocalNotification(notif);
    }
Esempio n. 9
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);
        }
Esempio n. 10
0
        //本地推送 你可以传入一个固定的推送时间
        public static void NotificationMessage(string message, System.DateTime newDate, bool isRepeatDay)
        {
#if UNITY_IPHONE
            CleanNotification();
            LocalNotification localNotification = new LocalNotification();
            localNotification.fireDate  = newDate;
            localNotification.alertBody = message;
            localNotification.applicationIconBadgeNumber = 1;
            localNotification.hasAction = true;
            if (isRepeatDay)
            {
                //是否每天定期循环
                localNotification.repeatCalendar = CalendarIdentifier.ChineseCalendar;
                localNotification.repeatInterval = CalendarUnit.Day;
            }
            localNotification.soundName = LocalNotification.defaultSoundName;
            NotificationServices.ScheduleLocalNotification(localNotification);
            MyDebug.LogWarning("DO通知:" + message + "," + newDate);
#endif
        }
Esempio n. 11
0
 //本地推送 你可以传入一个固定的推送时间
 public void NotificationMessage(string message, System.DateTime newDate, bool isRepeatDay)
 {
     //推送时间需要大于当前时间
     if (newDate > System.DateTime.Now)
     {
         LocalNotification localNotification = new LocalNotification();
         localNotification.fireDate  = newDate;
         localNotification.alertBody = message;
         localNotification.applicationIconBadgeNumber = 1;
         localNotification.hasAction = true;
         if (isRepeatDay)
         {
             //是否每天定期循环
             localNotification.repeatCalendar = CalendarIdentifier.ChineseCalendar;
             localNotification.repeatInterval = CalendarUnit.Day;
         }
         localNotification.soundName = LocalNotification.defaultSoundName;
         NotificationServices.ScheduleLocalNotification(localNotification);
     }
 }
Esempio n. 12
0
        /// <summary>
        ///     Sends a queue of notifications to the client
        /// </summary>
        public void Send()
        {
            Reset();
            foreach (var stamp in Enum.GetValues(typeof(IterationStamp)).Cast <IterationStamp>())
            {
                var notification = _notifications
                                   .FirstOrDefault(x => x.Condition.Invoke(stamp, _manny.Attribute));
#if UNITY_ANDROID
                NotificationUtil.Send(TimeSpan.FromMinutes((int)stamp), notification.Message);
#endif
#if UNITY_IPHONE
                var iosNotification = new LocalNotification {
                    fireDate    = DateTime.Now.AddMinutes((int)stamp),
                    alertBody   = notification.Message,
                    alertAction = "Manny"
                };
                NotificationServices.ScheduleLocalNotification(iosNotification);
#endif
            }
        }
Esempio n. 13
0
        private void iOSNotification(Notice notice)
        {
            System.DateTime newDate = System.DateTime.Now;
            if (notice.isDaily)
            {
                int h     = (int)notice.hour;
                var hour  = notice.hour - h;
                int year  = newDate.Year;
                int month = newDate.Month;
                int day   = newDate.Day;
                newDate = new System.DateTime(year, month, day, h, 0, 0).AddHours(hour);
                if (newDate <= System.DateTime.Now)
                {
                    newDate = newDate.AddDays(1);
                }
            }
            else
            {
                newDate = newDate.AddHours(notice.hour);
            }

            if (newDate > System.DateTime.Now)
            {
                LocalNotification localNotification = new LocalNotification();
                localNotification.fireDate  = newDate;
                localNotification.alertBody = notice.message;
                localNotification.applicationIconBadgeNumber = 1;
                localNotification.hasAction = true;
                localNotification.soundName = LocalNotification.defaultSoundName;
                if (notice.isDaily)
                {
                    localNotification.repeatCalendar = CalendarIdentifier.ChineseCalendar;
                    localNotification.repeatInterval = CalendarUnit.Day;
                }
                else
                {
                    listNtfs.Add(localNotification);
                }
                NotificationServices.ScheduleLocalNotification(localNotification);
            }
        }
Esempio n. 14
0
    /// <summary>
    /// Pushs the local message.
    /// </summary>
    /// <param name="dtime">Dtime.</param>
    /// <param name="alertBody">Alert body.</param>
    /// <param name="alertAction">Alert action.</param>
    /// <param name="alertLaunchImage">Alert launch image.</param>
    /// <param name="applicationIconBadgeNumber">Application icon badge number.</param>
    /// <param name="soundName">Sound name.</param>
    /// <param name="userinfo">Userinfo.</param>
    public void PushLocalMsg(DateTime dtime, string alertBody, string alertAction = "",
                             string alertLaunchImage = "", int applicationIconBadgeNumber = -1,
                             string soundName        = "", IDictionary userinfo = null
                             )
    {
        LocalNotification noti = new LocalNotification();

        noti.alertBody = alertBody;
        noti.fireDate  = dtime;

        if (alertAction != "")
        {
            noti.alertAction = alertAction;
        }
        if (alertLaunchImage != "")
        {
            noti.alertLaunchImage = alertLaunchImage;
        }
        if (applicationIconBadgeNumber != -1)
        {
            noti.applicationIconBadgeNumber = applicationIconBadgeNumber;
        }
        if (soundName != "")
        {
            noti.soundName = soundName;
        }
        if (userinfo != null)
        {
            noti.userInfo = userinfo;
        }

        if (dtime.Ticks == DateTime.Now.Ticks)
        {
            NotificationServices.PresentLocalNotificationNow(noti);
        }
        else
        {
            NotificationServices.ScheduleLocalNotification(noti);
        }
    }
Esempio n. 15
0
    /// <summary>
    /// Notifications the message.
    /// </summary>
    /// <param name="str">推送内容</param>
    /// <param name="nowDatatime">推送的时间</param>
    /// <param name="isRepeatDay">是否是定点</param>
    public static void NotificationMessage(string str, System.DateTime nowDatatime, bool isRepeatDay)
    {
        if (nowDatatime > System.DateTime.Now)
        {
            LocalNotification localNotification = new LocalNotification();
            localNotification.fireDate  = nowDatatime;
            localNotification.alertBody = str;
            localNotification.applicationIconBadgeNumber = localNotification.applicationIconBadgeNumber + 1;

            //localNotification.repeatInterval
            //localNotification.repeatInterval = CalendarUnit.Second;
            localNotification.hasAction = true;
            if (isRepeatDay)
            {
                //是否每天定期循环
                localNotification.repeatCalendar = CalendarIdentifier.ChineseCalendar;
                localNotification.repeatInterval = CalendarUnit.Day;
            }
            localNotification.soundName = LocalNotification.defaultSoundName;
            NotificationServices.ScheduleLocalNotification(localNotification);
        }
    }
    public static void ScheduleLocalNotification(GameLocalNotification notification)
    {
#if UNITY_IPHONE
        string title    = notification.GetTitle();
        bool   hasTitle = (title != null);
        if (title == null)
        {
            title = "";
        }

        LocalNotification localNotification = new LocalNotification();
        localNotification.alertAction = title;
        localNotification.alertBody   = notification.GetDescription();
        localNotification.fireDate    = notification.GetFireDate();
        localNotification.applicationIconBadgeNumber = 1;
        localNotification.soundName      = LocalNotification.defaultSoundName;
        localNotification.repeatInterval = (UnityEngine.CalendarUnit)(notification.GetRepeatInterval());
        localNotification.hasAction      = hasTitle;

        NotificationServices.ScheduleLocalNotification(localNotification);
#endif
    }
Esempio n. 17
0
    /// <summary>
    /// Setuje lokalnu notifikaciju
    /// </summary>
    /// <param name="timeOffset">Vreme u sekundama od tekuceg vremena kada treba prikazati notifikaciju</param>
    /// <param name="title">Naslov notifikacije</param>
    /// <param name="message">Telo (poruka) notifkacije</param>
    /// <param name="id">ID notifikacije.Za IOS ovo predstavlja redni broj na badge-u.</param>
    public void SetNottification(int timeOffset, string title, string message, int id)
    {
                #if UNITY_ANDROID && !UNITY_EDITOR
        using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
        {
            using (AndroidJavaObject obj_Activity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity"))
            {
                obj_Activity.Call("SendNotification", timeOffset.ToString(), title, message, id);
            }
        }
                #endif

                #if UNITY_IOS && !UNITY_EDITOR
        LocalNotification notification = new LocalNotification();
        notification.fireDate    = System.DateTime.Now.AddSeconds(timeOffset);
        notification.alertAction = title;
        notification.alertBody   = message;
        notification.hasAction   = false;
        notification.applicationIconBadgeNumber = id;
        NotificationServices.ScheduleLocalNotification(notification);
                #endif
    }
    //----------------------------------------------------------------------------
    //	@brief		ローカル通知設定
    //	@param[in]	string		(title)		通知文言:タイトル
    //	@param[in]	string		(text)		通知文言:本文
    //	@param[in]	int			(delay)		現在時刻から表示するまでの時間(秒)
    //----------------------------------------------------------------------------
    public static void SendNotification(string title, string text, int delay)
    {
        if (Patcher.Instance.GetLocalNotificationRegisterDisable())
        {
            return;
        }

        if (TimeManager.Instance == null)
        {
            return;
        }

#if LOCAL_NOTIFICATION_EDITOR
#if DEBUG_LOG
        // Editor
        Debug.Log("SetNotification: " + title + " / text: " + text + " / delay: " + delay);
#endif
#elif LOCAL_NOTIFICATION_ANDROID
        string package  = Application.identifier;
        string activity = "com.onevcat.uniwebview.AndroidPlugin";
        // Android
        ELANManager.SendNotification(title, text, package, activity, delay);
#elif LOCAL_NOTIFICATION_IOS
        // iOS(現在時刻とりなおして、ディレイ時間を足してるので若干登録時間に誤差がでるかも。気になるレベルではないはず)
        LocalNotification notification = new LocalNotification();
        if (notification != null)
        {
            // サーバー時間を加味して通知時間を変更している
            ulong    totalSeconds = TimeUtil.ConvertLocalTimeToServerTime(TimeManager.Instance.m_TimeNow.AddSeconds(delay));
            DateTime td           = TimeUtil.ConvertTotalSecondsToServerTime(totalSeconds);

            notification.applicationIconBadgeNumber = -1;
            notification.fireDate  = td;
            notification.alertBody = text;
            NotificationServices.ScheduleLocalNotification(notification);
        }
#endif
    }
Esempio n. 19
0
        /// <summary>
        /// Schedules a Local Notification based on given settings
        /// </summary>
        /// <param name="settings">Notification Settings used to create a Local Notification</param>
        public static void ScheduleNotification(NotificationSettings settings)
        {
#if UNITY_IOS
            if (NotificationServices.enabledNotificationTypes == NotificationType.None)
            {
                RegisterForNotifications();
            }

            DateTime dateTime = DateTime.Now;

            dateTime = dateTime.AddHours(settings.AdditionalHours);

            LocalNotification notification = new LocalNotification
            {
                alertAction = settings.ActionText,
                alertBody   = settings.BodyText,
                fireDate    = dateTime
            };

            NotificationServices.ScheduleLocalNotification(notification);
#elif UNITY_ANDROID
#endif
        }
Esempio n. 20
0
        public override void ScheduleNotification(int triggerInSeconds, string title, string text, int id, IDictionary <string, string> userData, string notificationProfile, int badgeNumber, ICollection <Button> buttons)
        {
            if (!CheckInitialized())
            {
                return;
            }

            LocalNotification notification = CreateLocalNotification(title, text, id, userData, notificationProfile, badgeNumber);

            notification.fireDate = System.DateTime.Now.AddSeconds(triggerInSeconds);
            if (m_enabled)
            {
                NotificationServices.ScheduleLocalNotification(notification);
            }
            else
            {
                if (m_scheduledNotificationsWhenDisabled == null)
                {
                    m_scheduledNotificationsWhenDisabled = new List <ScheduledNotification>();
                }
                m_scheduledNotificationsWhenDisabled.Add(ToScheduledNotification(notification, DateTime.Now));
                SaveScheduledNotificationsWhenDisabled();
            }
        }
Esempio n. 21
0
    /////////////////////////////////////////////////////////////////////

    // 添加本地推送信息
    // @params: alterAction - 推送标题
    // @params: alterBody - 推送信息
    // @params: fireDate - 推送发送日
    // @return: true添加成功,false添加失败
#if UNITY_IPHONE
    public bool Add(string alterAction, string alterBody, System.DateTime fireDate, bool loop_day)
    {
        LocalNotification notification = new LocalNotification();

        //notification.alertAction = alterAction;
        notification.alertBody = alterBody;
        notification.fireDate  = fireDate;
        notification.soundName = LocalNotification.defaultSoundName;

        if (loop_day)
        {
            notification.repeatInterval = CalendarUnit.Day;
        }
        else
        {
            notification.repeatInterval = CalendarUnit.Weekday;
        }

        NotificationServices.ScheduleLocalNotification(notification);

        Debug.Log("Add local notification, fire date: " + fireDate);

        return(true);
    }
    /// <summary>
    /// 本地推送 你可以传入一个固定的推送时间
    /// </summary>
    /// <param name="_message"></param>
    /// <param name="_date"></param>
    /// <param name="_isRepeatDay"></param>
    internal void NotificationMessage(int _id, string _title, string _message,
                                      DateTime _date, bool _isRepeatDay)
    {
        // 推送时间需要大于当前时间
        if (_date <= System.DateTime.Now)
        {
            // 往前翻一天
            _date = _date.AddDays(1);
        }

#if UNITY_IPHONE || NEW_EGSDK_IOS
        // 推送时间需要大于当前时间
        // if (_date > System.DateTime.Now)
        {
            UnityEngine.LocalNotification localNotification = new UnityEngine.LocalNotification();
            localNotification.fireDate  = _date;
            localNotification.alertBody = _message;
            localNotification.applicationIconBadgeNumber = 1;
            localNotification.hasAction   = true;
            localNotification.alertAction = _title;

            if (_isRepeatDay)
            {
                // 是否每天定期循环
                localNotification.repeatCalendar = CalendarIdentifier.ChineseCalendar;
                localNotification.repeatInterval = CalendarUnit.Day;
            }

            localNotification.soundName = UnityEngine.LocalNotification.defaultSoundName;
            NotificationServices.ScheduleLocalNotification(localNotification);
        }
#endif

#if UNITY_ANDROID || NEW_EGSDK_ANDROID
        // 前面已经前翻一天
        // if (_date > System.DateTime.Now)
        {
            long _delay;

            //if (_date.Hour >= 12)
            //{
            //    _delay = __SECONDOFDAY - ((_date.Hour - 12) * __SECONDOFHOUR + _date.Minute * __SECONDOFMINUTE + _date.Second);
            //}
            //else
            //{
            //    _delay = (12 - _date.Hour) * __SECONDOFHOUR - _date.Minute * __SECONDOFMINUTE - _date.Second;
            //}

            // 计算时间差 目标时间-当前时间获取时间差
            TimeSpan _ts = (TimeSpan)(_date - System.DateTime.Now);

            _delay = (long)_ts.TotalSeconds;

            DebugLog.Log("dateTime:" + _date.ToString());

            DebugLog.Log("delay:" + _delay);

            if (_isRepeatDay)
            {
                AndroidLocalNotification.SendRepeatingNotification(_id, _delay, __SECONDOFDAY, _title,
                                                                   _message,
                                                                   new Color32(0xff, 0x44, 0x44, 255),
                                                                   true, true, true);
            }
            else
            {
                AndroidLocalNotification.SendNotification(_id, _delay,
                                                          _title,
                                                          _message,
                                                          new Color32(0xff, 0x44, 0x44, 255),
                                                          true, true, true);
            }
        }
#endif
    }
Esempio n. 23
0
        //Please note that the actual interval may be different.
        //On iOS there are only fixed options like every minute, every day, every week and so on. So the provided <c>intervalSeconds</c> value will be approximated by one of the available options.
        public override void ScheduleNotificationRepeating(int firstTriggerInSeconds, int intervalSeconds, string title, string text, int id, IDictionary <string, string> userData, string notificationProfile, int badgeNumber, ICollection <Button> buttons)
        {
            if (!CheckInitialized())
            {
                return;
            }

            LocalNotification notification = CreateLocalNotification(title, text, id, userData, notificationProfile, badgeNumber);

            notification.fireDate = System.DateTime.Now.AddSeconds(firstTriggerInSeconds);
            if (intervalSeconds < 3)
            {
                //Approximate it to every second if the desired intervalSeconds is less then 3 seconds
                notification.repeatInterval = CalendarUnit.Second;
            }
            else if (intervalSeconds < 3 * 60)
            {
                //Approximate it to every minute if the desired intervalSeconds is less then 3 minutes
                notification.repeatInterval = CalendarUnit.Minute;
            }
            else if (intervalSeconds < 3 * 60 * 60)
            {
                //Approximate it to every hour if the desired intervalSeconds is less then 3 hours
                notification.repeatInterval = CalendarUnit.Hour;
            }
            else if (intervalSeconds < 3 * 24 * 60 * 60)
            {
                //Approximate it to every day if the desired intervalSeconds is less then 3 days
                notification.repeatInterval = CalendarUnit.Day;
            }
            else if (intervalSeconds < 3 * 7 * 24 * 60 * 60)
            {
                //Approximate it to every week if the desired intervalSeconds is less then 3 weeks
                notification.repeatInterval = CalendarUnit.Week;
            }
            else if (intervalSeconds < 2 * 31 * 24 * 60 * 60)
            {
                //Approximate it to every month if the desired intervalSeconds is less then 2 months
                notification.repeatInterval = CalendarUnit.Month;
            }
            else if (intervalSeconds < 183 * 24 * 60 * 60)
            {
                //Approximate it to every quarter if the desired intervalSeconds is less then half a year
                notification.repeatInterval = CalendarUnit.Quarter;
            }
            else if (intervalSeconds < 3 * 365 * 24 * 60 * 60)
            {
                //Approximate it to every year if the desired intervalSeconds is less then 3 years
                notification.repeatInterval = CalendarUnit.Year;
            }
            else
            {
                UnityEngine.Debug.LogWarning("Suspicious intervalSeconds value provided: " + intervalSeconds);
                notification.repeatInterval = CalendarUnit.Era;
            }

            if (m_enabled)
            {
                NotificationServices.ScheduleLocalNotification(notification);
            }
            else
            {
                if (m_scheduledNotificationsWhenDisabled == null)
                {
                    m_scheduledNotificationsWhenDisabled = new List <ScheduledNotification>();
                }
                m_scheduledNotificationsWhenDisabled.Add(ToScheduledNotification(notification, DateTime.Now));
                SaveScheduledNotificationsWhenDisabled();
            }
        }
Esempio n. 24
0
        //private
        private void SetNotificationsEnabled(bool enabled, bool inInitialization)
        {
            UnityEngine.PlayerPrefs.SetInt(m_enabledOptionName, enabled ? 1 : 0);

            if (!inInitialization && !Initialized)
            {
                if (!enabled)
                {
                    NotificationServices.UnregisterForRemoteNotifications();
                }

                return;
            }

            if (m_enabled == enabled)
            {
                return;
            }

            m_enabled = enabled;

            if (enabled)
            {
                RegisterForNotifications();

                if (m_scheduledNotificationsWhenDisabled != null)
                {
                    DateTime now = DateTime.Now;

                    foreach (var scheduledNotification in m_scheduledNotificationsWhenDisabled)
                    {
                        LocalNotification notification = new LocalNotification();
                        if (scheduledNotification.badgeNumber >= 0)
                        {
                            notification.applicationIconBadgeNumber = scheduledNotification.badgeNumber;
                        }
                        notification.alertAction = scheduledNotification.alertAction;
                        notification.alertBody   = scheduledNotification.alertBody;
                        notification.hasAction   = true;
                        notification.soundName   = scheduledNotification.soundName;
                        notification.userInfo    = (scheduledNotification.userData != null) ? scheduledNotification.userData : new Dictionary <string, string>();
                        if (scheduledNotification.fireDate > now)
                        {
                            notification.fireDate = scheduledNotification.fireDate;
                        }
                        else if (scheduledNotification.fireDate != DateTime.MinValue)
                        {
                            notification.fireDate = DateTime.Now.AddSeconds(2);
                        }
                        else
                        {
                            notification.fireDate = RepeatIntervalToDateTime(scheduledNotification.repeatInterval);
                        }
                        notification.repeatInterval = scheduledNotification.repeatInterval;

                        NotificationServices.ScheduleLocalNotification(notification);
                    }

                    m_scheduledNotificationsWhenDisabled = null;
                    SaveScheduledNotificationsWhenDisabled();
                }

                if (!inInitialization)
                {
                    SetBadge(GetBadge());
                }
            }
            else
            {
                List <ScheduledNotification> scheduledNotificationsWhenDisabled;
                if (NotificationServices.scheduledLocalNotifications != null && NotificationServices.scheduledLocalNotifications.Length != 0)
                {
                    scheduledNotificationsWhenDisabled = new List <ScheduledNotification>(NotificationServices.scheduledLocalNotifications.Length);

                    DateTime now = DateTime.Now;

                    foreach (var notification in NotificationServices.scheduledLocalNotifications)
                    {
                        scheduledNotificationsWhenDisabled.Add(ToScheduledNotification(notification, now));
                    }
                }
                else
                {
                    scheduledNotificationsWhenDisabled = null;
                }

                CancelAllNotifications();
                NotificationServices.UnregisterForRemoteNotifications();

                if (scheduledNotificationsWhenDisabled != null)
                {
                    m_scheduledNotificationsWhenDisabled = scheduledNotificationsWhenDisabled;
                    SaveScheduledNotificationsWhenDisabled();
                }

                _UT_SetIconBadgeNumber(0);
            }
        }
    public void OnApplicationPause(bool pause)
    {
        if (pause)
        {
                        #if Add_AD
            if (DataPlayerController.getInstance().data.DelAD == 0)
            {
                IOSAD.showInterstitialMoGo();
            }
                        #endif

            DataPlayerController.getInstance().saveDataPlayer();

                        #if UNITY_IPHONE || UNITY_IOS
            System.DateTime today = System.DateTime.Now;


            int canGotNum = Mathf.Max(WGConfig.AUTO_ADD_MAX - _DataPlayer.Coin, 0) / 10;
            if (canGotNum > 0)
            {
                for (int i = 0; i < canGotNum; i++)
                {
                    LocalNotification ln = new LocalNotification();
                    ln.applicationIconBadgeNumber = (i + 1) * 10;

                    System.DateTime answer = today.AddSeconds((i + 1) * 60);

                    ln.fireDate = answer;

                    NotificationServices.ScheduleLocalNotification(ln);
                }
            }

            today = System.DateTime.Now;

            int hour = 24 - today.Hour;
            int min  = 10 + 60 - today.Minute;


            LocalNotification ln1 = new LocalNotification();
            ln1.alertBody   = WGStrings.getText(1036);
            ln1.alertAction = WGStrings.getText(1037);
            ln1.hasAction   = true;
            ln1.fireDate    = today.Add(new System.TimeSpan(hour, min, 0));
            ln1.soundName   = LocalNotification.defaultSoundName;

            NotificationServices.ScheduleLocalNotification(ln1);
                        #endif

            MDDataCoin dc = DataCoinController.getInstance().data;

            dc.CoinID.Clear();
            dc.CoinPos.Clear();
            dc.CoinRoto.Clear();
            for (int i = 0, max = cs_ObjManager._szLiveCoin.Count; i < max; i++)
            {
                BCGameObj go = cs_ObjManager._szLiveCoin[i].GetComponent <BCGameObj>();
                dc.CoinID.Add(go.ID);
                dc.CoinPos.Add(SDK.to3Float(go.transform.position));
                dc.CoinRoto.Add(SDK.to3Float(go.transform.localEulerAngles));
            }
            DataCoinController.getInstance().saveDataCoin();

#if TalkingData
//			int[] szDa = new int[]{10000,90000,80000,70000,60000,50000,40000,30000,20000,10000,8000,6000,4000,2000,};
//			Dictionary<string, object> dic = new Dictionary<string, object>();
//			if(mGotCoinNum>100000)
//			{
//				dic.Add("getCoinNum", "10w");
//
//			}
//			else if(mGotCoinNum>90000)
//			{
//				dic.Add("getCoinNum","9w_10w");
//			}
//			else if(mGotCoinNum>80000)
//			{
//				dic.Add("getCoinNum","8w_9w");
//			}
////			else if(mGotCoinNum>
//			TalkingDataGA.OnEvent(WGStrings.getText(9001), dic);
#endif
        }
        else
        {
                        #if Add_AD
            if (DataPlayerController.getInstance().data.DelAD == 0)
            {
                IOSAD.readyInterstitialAds();
            }
                        #endif
            mGotCoinNum = 0;
            CleanNotification();
            CheckDefenseTime();
        }
    }
Esempio n. 26
0
        public override void RepeatNotification(string message, DateTime time)
        {
            LocalNotification ntf = NewNotification(message, time, CalendarUnit.Day);

            NotificationServices.ScheduleLocalNotification(ntf);
        }
Esempio n. 27
0
        public override void ScheduleNotification(string message, DateTime time)
        {
            LocalNotification ntf = NewNotification(message, time);

            NotificationServices.ScheduleLocalNotification(ntf);
        }
Esempio n. 28
0
    void INotificationInterchange.SendNotification(PPNotification notification)
    {
        LocalNotification iOSNotification = register.RegisterNotification(notification);

        NotificationServices.ScheduleLocalNotification(iOSNotification);
    }