ScheduleLocalNotification() private method

private ScheduleLocalNotification ( LocalNotification notification ) : void
notification LocalNotification
return void
コード例 #1
0
        // Call by main game OnApplicationPause
        public void ScheduleReturnBackToGameNotification()
        {
#if UNITY_ANDROID
            NotificationParams notification = new NotificationParams
            {
                Id             = NotificationIdHandler.GetNotificationId(),
                Ticker         = "Ticker",
                Sound          = true,
                Vibrate        = true,
                Light          = true,
                LargeIcon      = "app_icon",
                SmallIcon      = NotificationIcon.Heart,
                SmallIconColor = new Color(0, 0.5f, 0),
                CallbackData   = "ScheduleReturnBackToGameNotification", // name of method

                Delay   = TimeSpan.FromSeconds(inactiveLatelyNotificationDelayInSeconds),
                Title   = androidAppTitle,
                Message = inactiveLatelyMessage
            };
            NotificationManager.SendCustom(notification);
#elif UNITY_IOS
            LocalNotification notification = new LocalNotification
            {
                applicationIconBadgeNumber = 1,
                alertBody = inactiveLatelyMessage,
                fireDate  = DateTime.Now.AddSeconds(inactiveLatelyNotificationDelayInSeconds),
                soundName = LocalNotification.defaultSoundName
            };
            NotificationServices.ScheduleLocalNotification(notification);
#endif
        }
コード例 #2
0
    private void sendNotification(int id, TimeSpan delay, string title, string text, Color32 color)
    {
        var notificationParams = new NotificationParams {
            Id      = id,
            Delay   = delay,
            Title   = title,
            Message = text,
            //Ticker = "Ticker",
            Sound          = true,
            Vibrate        = true,
            Light          = true,
            SmallIcon      = NotificationIcon.Bell,
            SmallIconColor = new Color(0.5f, 0.5f, 0.5f),
            LargeIcon      = "app_icon"
        };

        NotificationManager.SendCustom(notificationParams);
        //NotificationManager.SendWithAppIcon(delay, title, text, new Color(0, 0.6f, 1), NotificationIcon.Bell);
        //NotificationManager.Send(delay, title, text, new Color(0, 0.6f, 1));
        //LocalNotification.SendNotification(id, delay, title, text, color);

#if UNITY_IOS
        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            UnityEngine.iOS.LocalNotification notification = new UnityEngine.iOS.LocalNotification();
            notification.fireDate    = DateTime.Now.Add(delay);
            notification.alertAction = "Alert";
            notification.alertBody   = text;
            notification.hasAction   = false;
            NotificationServices.ScheduleLocalNotification(notification);
        }
#endif
    }
コード例 #3
0
    public void PostIOSLocalNotification(DateTime time, string message)
    {
        var notif = new Local();

        notif.fireDate  = time;
        notif.alertBody = message;
        Notification.ScheduleLocalNotification(notif);
    }
コード例 #4
0
 public void AddNotification()
 {
     #if UNITY_IOS
     LocalNotification l = new LocalNotification();
     l.applicationIconBadgeNumber = 1;
     l.fireDate = System.DateTime.Now.AddSeconds(pushSeconds[0]);
     NotificationServices.ScheduleLocalNotification(l);
     #endif
 }
コード例 #5
0
    public static void SetNotification(string message, int delayTime, int badgeNumber = 1)
    {
        var l = new LocalNotification();

        l.applicationIconBadgeNumber = badgeNumber;
        l.fireDate  = System.DateTime.Now.AddSeconds(delayTime);
        l.alertBody = message;
        NotificationServices.ScheduleLocalNotification(l);
    }
コード例 #6
0
 public void ScheduleLocalPushNotification(string title, string message, DateTime dateTime)
 {
     NotificationServices.ScheduleLocalNotification(new UnityEngine.iOS.LocalNotification()
     {
         alertAction = title,
         alertBody   = message,
         fireDate    = dateTime,
     });
 }
コード例 #7
0
        private void SetNotify()
        {
            foreach (var info in notifications.Values)
            {
                var localNotification = new LocalNotification();

                localNotification.fireDate    = info.UnixTime.UnixTimeToDateTime();
                localNotification.alertBody   = info.Message;
                localNotification.alertAction = info.Title;

                NotificationServices.ScheduleLocalNotification(localNotification);
            }
        }
コード例 #8
0
 public void setLocalNotification(int hour, int min, string alAct)     // 通知設定
 {
             #if UNITY_IOS
     LocalNotification simpleNotification = new LocalNotification();
     simpleNotification.alertAction = alAct;
     simpleNotification.alertBody   = hour + ":" + (min).ToString("00") + " It's time to stydy!!";
     simpleNotification.applicationIconBadgeNumber = 1;
     DateTime dt = DateTime.Now;
     if (hour < dt.Hour)
     {
         dt = dt.AddDays(1);
     }
     simpleNotification.fireDate = new DateTime(dt.Year, dt.Month, dt.Day, hour, min, 0, DateTimeKind.Local);
     NotificationServices.ScheduleLocalNotification(simpleNotification);
             #endif
 }
コード例 #9
0
        private void ScheduleNotification(Notification notification)
        {
            //UDBG.Log(notification.ToString());

#if UNITY_ANDROID
            Assets.SimpleAndroidNotifications.NotificationManager.SendWithAppIcon(notification.Delay, notification.Title, notification.Content, Color.black, Assets.SimpleAndroidNotifications.NotificationIcon.Dollar);
#endif

#if UNITY_IOS
            NotificationServices.ScheduleLocalNotification(new UnityEngine.iOS.LocalNotification()
            {
                fireDate  = DateTime.Now.Add(notification.Delay),
                alertBody = notification.Content,
                soundName = "default"
            });
#endif
        }
コード例 #10
0
        // Call by main game OnApplicationPause
        public void ScheduleOneDayNotification()
        {
            string dayNotificationScheduleTime = PlayerPrefs.GetString(Constants.Notifications.DayNotificationScheduleTime, "");

            if (dayNotificationScheduleTime != "")
            {
                DateTime scheduledOneDayNotificationTime = DateTime.ParseExact(dayNotificationScheduleTime, "yyyyMMddHHmmss", CultureInfo.CurrentCulture);
                TimeSpan timeSpan = scheduledOneDayNotificationTime - DateTime.Now;

                if (timeSpan.TotalSeconds > 0)
                {
#if UNITY_ANDROID
                    NotificationParams notification = new NotificationParams
                    {
                        Id             = NotificationIdHandler.GetNotificationId(),
                        Ticker         = "Ticker",
                        Sound          = true,
                        Vibrate        = true,
                        Light          = true,
                        LargeIcon      = "app_icon",
                        SmallIcon      = NotificationIcon.Heart,
                        SmallIconColor = new Color(0, 0.5f, 0),
                        Delay          = TimeSpan.FromSeconds(timeSpan.TotalSeconds),
                        Title          = androidAppTitle,
                        Message        = Random24HourMessage()
                    };
                    NotificationManager.SendCustom(notification);
#elif UNITY_IOS
                    if (notificationsOn)
                    {
                        LocalNotification notification = new LocalNotification
                        {
                            applicationIconBadgeNumber = 1,
                            alertBody = Random24HourMessage(),
                            fireDate  = DateTime.Now.AddSeconds(timeSpan.TotalSeconds),
                            soundName = LocalNotification.defaultSoundName
                        };
                        NotificationServices.ScheduleLocalNotification(notification);
                    }
#endif
                }
            }
        }
コード例 #11
0
    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(), 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
    }
コード例 #12
0
 public static void NotificationMessage(string message, DateTime newDate, bool isRepeateDay)
 {
             #if UNITY_IOS
     //大于当前时间进行推送
     if (newDate > DateTime.Now)
     {
         mIconBadgeNumber++;
         LocalNotification localNotification = new LocalNotification();
         localNotification.alertAction = "CNM,看这里!!!";
         localNotification.fireDate    = newDate;
         localNotification.alertBody   = message;
         localNotification.applicationIconBadgeNumber = mIconBadgeNumber;
         localNotification.hasAction = true;
         if (isRepeateDay)
         {
             localNotification.repeatCalendar = CalendarIdentifier.ChineseCalendar;
             localNotification.repeatInterval = CalendarUnit.Day;
         }
         localNotification.soundName = LocalNotification.defaultSoundName;
         NotificationServices.ScheduleLocalNotification(localNotification);
     }
     Debug.Log(mIconBadgeNumber);
             #endif
 }
コード例 #13
0
        public void ScheduleFilmReplenishmentNotification(double secondsUntilFull)
        {
            if ((int)secondsUntilFull > 0)
            {
                if (notificationsOn)
                {
                    secondsUntilFull = Mathf.Round((float)BedtimeCheck(secondsUntilFull));
#if UNITY_ANDROID
                    NotificationParams notification = new NotificationParams
                    {
                        Id             = NotificationIdHandler.GetNotificationId(),
                        Ticker         = "Ticker",
                        Sound          = true,
                        Vibrate        = true,
                        Light          = true,
                        LargeIcon      = "app_icon",
                        SmallIcon      = NotificationIcon.Event,
                        SmallIconColor = new Color(0, 0.5f, 0),
                        Delay          = TimeSpan.FromSeconds(secondsUntilFull),
                        Title          = androidAppTitle,
                        Message        = RandomFilmReplenishmentMessage()
                    };
                    NotificationManager.SendCustom(notification);
#elif UNITY_IOS
                    LocalNotification notification = new LocalNotification
                    {
                        applicationIconBadgeNumber = 1,
                        alertBody = RandomFilmReplenishmentMessage(),
                        fireDate  = DateTime.Now.AddSeconds((int)secondsUntilFull),
                        soundName = LocalNotification.defaultSoundName
                    };
                    NotificationServices.ScheduleLocalNotification(notification);
#endif
                }
            }
        }
コード例 #14
0
    void Update()
    {
        if (Time.time > 2 && auctionwait == false)
        {
            auctionopen = true;
        }
        //check pre-auction wait is over or not
        if (auctionwait == true && (Time.time - auctiontime) > 10)
        {
            auctionend = true;
        }
        //check auction is over or not
        if (NotificationServices.localNotificationCount > 0)
        {
            Debug.Log(NotificationServices.localNotifications[0].alertBody);
            NotificationServices.ClearLocalNotifications();
        }
        //push iOS notifications
        if ((Time.time / 60) % 5 == 0)
        {
            var notif = new LocalNotification();
            notif.fireDate = System.DateTime.Now.AddSeconds(0);
            var rad = (int)Random.Range(0, 9);
            switch (rad)
            {
            case 0:
                randomnewstext = "NewsTexts0";
                break;

            case 1:
                randomnewstext = "NewsTexts1";
                break;

            case 2:
                randomnewstext = "NewsTexts2";
                break;

            case 3:
                randomnewstext = "NewsTexts3";
                break;

            case 4:
                randomnewstext = "NewsTexts4";
                break;

            case 5:
                randomnewstext = "NewsTexts5";
                break;

            case 6:
                randomnewstext = "NewsTexts6";
                break;

            case 7:
                randomnewstext = "NewsTexts7";
                break;

            case 8:
                randomnewstext = "NewsTexts8";
                break;

            case 9:
                randomnewstext = "NewsTexts9";
                break;
            }
            notif.alertBody = randomnewstext;
            NotificationServices.ScheduleLocalNotification(notif);
            // random news event iOS notification to be delivered for every 5 minutes
        }
    }
コード例 #15
0
    /// <summary>
    /// Local recurring notification. Recurring weekly once you havent touched the app in more than 7 days
    /// Also populates rate app notification
    /// </summary>
    public void ScheduleLocalNotification()
    {
                #if UNITY_IOS
        // Reset the badge icon
        UnityEngine.iOS.LocalNotification resetNotif = new UnityEngine.iOS.LocalNotification();
        resetNotif.applicationIconBadgeNumber = -1;
        resetNotif.hasAction = false;
        NotificationServices.PresentLocalNotificationNow(resetNotif);

        // Clear and cancel
        NotificationServices.ClearLocalNotifications();                                                            // Clear all received notifications
        foreach (UnityEngine.iOS.LocalNotification localNotif in NotificationServices.scheduledLocalNotifications) // Remove reminder notifications
        {
            if (localNotif.repeatInterval == UnityEngine.iOS.CalendarUnit.Week)
            {
                NotificationServices.CancelLocalNotification(localNotif);
                Debug.Log("CANCELLING RECURRING NOTIFICATIONS");
            }
        }

        // Prepare to fire new notification
        string iOSAction = "visit " + DataManager.Instance.GameData.PetInfo.PetName;            // Action (ie. slide to _)
        string iOSBody   = DataManager.Instance.GameData.PetInfo.PetName + " misses you!";

        DateTime fireDate = LgDateTime.GetTimeNow().AddDays(7);                 // Schedule for 7 days from now

        UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification();
        notif.fireDate                   = fireDate;
        notif.alertAction                = iOSAction;
        notif.alertBody                  = iOSBody;
        notif.soundName                  = UnityEngine.iOS.LocalNotification.defaultSoundName;
        notif.repeatInterval             = UnityEngine.iOS.CalendarUnit.Week;
        notif.applicationIconBadgeNumber = -1;
        NotificationServices.ScheduleLocalNotification(notif);


        // Also check if we need to push the rate app notification
        // Conditions - passed day 7 retention, only seen once
        TimeSpan difference = LgDateTime.GetTimeNow().Subtract(DataManager.Instance.GameData.PlayPeriod.FirstPlayPeriod);
        if (!DataManager.Instance.GameData.PlayPeriod.IsDisplayedAppNotification &&                     // Displayed for first time
            DataManager.Instance.GameData.PlayPeriod.IsFirstPlayPeriodAux &&                            // Started first play session in
            difference > new TimeSpan(7, 0, 0, 0))                                                      // Past 7 days

        {
            UnityEngine.iOS.LocalNotification rateNotif = new UnityEngine.iOS.LocalNotification();

            // Shoot for next 8:47am
            DateTime now        = LgDateTime.GetTimeNow();
            DateTime today847am = now.Date.AddHours(8).AddMinutes(47);
            DateTime next847am  = now <= today847am ? today847am : today847am.AddDays(1);

            rateNotif.fireDate    = next847am;
            rateNotif.alertAction = "open game";
            rateNotif.alertBody   = "Is 'Wizdy Pets' helping your kids with asthma? Leave us a review in the AppStore!";
            rateNotif.soundName   = UnityEngine.iOS.LocalNotification.defaultSoundName;
            rateNotif.applicationIconBadgeNumber = -1;

            NotificationServices.ScheduleLocalNotification(rateNotif);
            DataManager.Instance.GameData.PlayPeriod.IsDisplayedAppNotification = true;
        }
#endif

#if UNITY_ANDROID && !UNITY_EDITOR
        string title = DataManager.Instance.GameData.PetInfo.PetName + " misses you!";
        string body  = "Why not stop by and visit?";

        AndroidNotifications.cancelNotification(1);
        int id = 1;
        NotificationBuilder build    = new NotificationBuilder(id, title, body);
        TimeSpan            interval = new TimeSpan(168, 0, 0);
        build.setInterval(interval);
        build.setAutoCancel(false);
        build.setDelay(interval);
        AndroidNotifications.scheduleNotification(build.build());
#endif
    }
コード例 #16
0
    public void UpdateNotifications()
    {
        if (LocalizationAssistant.Instance == null)
        {
            return;
        }

        #region Android
#if UNITY_ANDROID
        string raw = PlayerPrefs.GetString("NotificationIDs");
        if (!string.IsNullOrEmpty(raw))
        {
            notification_ids = raw.Split(',').Select(x => x.Split(':')).ToDictionary(x => x[0], x => int.Parse(x[1]));
        }
        else
        {
            notification_ids = new Dictionary <string, int>();
        }



        PlayerPrefs.SetString("NotificationIDs", string.Join(",", notification_ids.Select(x => string.Format("{0}:{1}", x.Key, x.Value)).ToArray()));
        PlayerPrefs.Save();
#endif
        #endregion

        #region iOS
#if UNITY_IOS
        RemoveAllNotifications();
        LocalNotification notification;

        // Daily reward
        if (ProfileAssistant.main != null && ProfileAssistant.main.local_profile != null)
        {
            notification                = new LocalNotification();
            notification.fireDate       = DateTime.Now + Utils.GetDelay(daily_reward_hour, 0, 0);
            notification.repeatInterval = UnityEngine.iOS.CalendarUnit.Day;
            notification.alertBody      = LocalizationAssistant.main["notification_dailyreward_text"];
            notification.soundName      = LocalNotification.defaultSoundName;
            NotificationServices.ScheduleLocalNotification(notification);
        }

        // Lifes
        if (ProfileAssistant.main != null && ProfileAssistant.main.local_profile != null)
        {
            if ((ProfileAssistant.main.local_profile.next_life_time - DateTime.Now).TotalSeconds > 30)
            {
                notification           = new LocalNotification();
                notification.fireDate  = ProfileAssistant.main.local_profile.next_life_time;
                notification.alertBody = LocalizationAssistant.main["notification_lifesrefilled_text"];
                notification.soundName = LocalNotification.defaultSoundName;
                NotificationServices.ScheduleLocalNotification(notification);
            }
        }

        // Good morning
        if (ProfileAssistant.main != null && ProfileAssistant.main.local_profile != null)
        {
            notification                = new LocalNotification();
            notification.fireDate       = DateTime.Now + Utils.GetDelay(9, 0, 0);
            notification.repeatInterval = UnityEngine.iOS.CalendarUnit.Day;
            notification.alertBody      = LocalizationAssistant.main["notification_goodmorning_text"];
            notification.soundName      = LocalNotification.defaultSoundName;
            NotificationServices.ScheduleLocalNotification(notification);
        }

        // Test
        notification           = new LocalNotification();
        notification.fireDate  = DateTime.Now + new TimeSpan(0, 1, 0);
        notification.alertBody = "Test \ue012";
        NotificationServices.ScheduleLocalNotification(notification);
#endif
        #endregion
    }