private UnityEngine.iOS.LocalNotification PrepareNotificationObject(string id, DateTime when, ILocalNotification notification)
        {
            UnityEngine.iOS.LocalNotification notificationObject = new UnityEngine.iOS.LocalNotification();

            notificationObject.userInfo.Add("id", id);

            notificationObject.fireDate    = when;
            notificationObject.alertAction = notification.message;
            notificationObject.alertBody   = notification.message;

            if (notification.useSound)
            {
                if (notification.customSoundName != null)
                {
                    notificationObject.soundName = notification.customSoundName;
                }
                else
                {
                    notificationObject.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName;
                }
            }

            var iosExtension = notification.GetExtension <INotificationExtensionIOS>(false);

            if (iosExtension != null)
            {
                notificationObject.hasAction = iosExtension.hasAction;
                notificationObject.applicationIconBadgeNumber = iosExtension.applicationIconBadgeNumber;


                if (iosExtension.repeatInterval != RepeatInterval.None)
                {
                    switch (iosExtension.repeatInterval)
                    {
                    case RepeatInterval.Era:                notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Era;               break;

                    case RepeatInterval.Year:               notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Year;              break;

                    case RepeatInterval.Month:              notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Month;             break;

                    case RepeatInterval.Day:                notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Day;               break;

                    case RepeatInterval.Hour:               notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Hour;              break;

                    case RepeatInterval.Minute:             notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Minute;            break;

                    case RepeatInterval.Second:             notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Second;            break;

                    case RepeatInterval.Week:               notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Week;              break;

                    case RepeatInterval.Weekday:            notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Weekday;           break;

                    case RepeatInterval.WeekdayOrdinal:     notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.WeekdayOrdinal;    break;

                    case RepeatInterval.Quarter:            notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Quarter;           break;
                    }

                    switch (iosExtension.repeatCalendar)
                    {
                    case CalendarIdentifier.GregorianCalendar:          notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.GregorianCalendar;       break;

                    case CalendarIdentifier.BuddhistCalendar:           notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.BuddhistCalendar;        break;

                    case CalendarIdentifier.ChineseCalendar:            notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ChineseCalendar;         break;

                    case CalendarIdentifier.HebrewCalendar:             notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.HebrewCalendar;          break;

                    case CalendarIdentifier.IslamicCalendar:            notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.IslamicCalendar;         break;

                    case CalendarIdentifier.IslamicCivilCalendar:       notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.IslamicCivilCalendar;    break;

                    case CalendarIdentifier.JapaneseCalendar:           notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.JapaneseCalendar;        break;

                    case CalendarIdentifier.RepublicOfChinaCalendar:    notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.RepublicOfChinaCalendar; break;

                    case CalendarIdentifier.PersianCalendar:            notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.PersianCalendar;         break;

                    case CalendarIdentifier.IndianCalendar:             notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.IndianCalendar;          break;

                    case CalendarIdentifier.ISO8601Calendar:            notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ISO8601Calendar;         break;
                    }
                }
            }

            return(notificationObject);
        }
Esempio n. 2
0
        public override void ScheduleLocalNotification
            (string id
            , DateTime when
            , ILocalNotification notification
            , bool cancelPrevious)
        {
            ScheduleMode scheduleMode   = ScheduleMode.None;
            TimeSpan     repeatInterval = TimeSpan.Zero;

            Android.LocalNotifications.NotificationData notificationObject = new Android.LocalNotifications.NotificationData(notification.title, notification.message);

            notificationObject.SetUseSound(notification.useSound);
            notificationObject.SetCustomSoundName(notification.customSoundName);

            var androidExtension = notification.GetExtension <INotificationExtensionAndroid>(false);

            if (androidExtension != null)
            {
                scheduleMode   = androidExtension.scheduleMode;
                repeatInterval = androidExtension.repeatInterval;

                notificationObject.SetTicker(androidExtension.ticker);

                notificationObject.SetSubText(androidExtension.subText);
                notificationObject.SetProgressMax(androidExtension.progressMax);

                notificationObject.SetProgressMax(androidExtension.progressMax);
                notificationObject.SetProgress(androidExtension.progress);
                notificationObject.SetProgressIndeterminate(androidExtension.progressIndeterminate);

                notificationObject.SetGroup(androidExtension.group);
                notificationObject.SetIsGroupSummary(androidExtension.isGroupSummary);
                notificationObject.SetCategory((Android.LocalNotifications.NotificationData.Category)androidExtension.category);

                notificationObject.SetAutoCancel(androidExtension.autoCancel);
                notificationObject.SetLocalOnly(androidExtension.localOnly);
                notificationObject.SetOngoing(androidExtension.ongoing);
                notificationObject.SetOnlyAlertOnce(androidExtension.onlyAlertOnce);
                notificationObject.SetPriority((Android.LocalNotifications.NotificationData.Priority)androidExtension.priority);

                notificationObject.SetShowWhen(androidExtension.showWhen);
                notificationObject.SetWhenIsChronometer(androidExtension.whenIsChronometer);
                notificationObject.SetChronometerCountdown(androidExtension.chronometerCountdown);
                notificationObject.SetCustomWhenDate(androidExtension.customWhenDate);
                notificationObject.SetCustomWhenChronometer(androidExtension.customWhenChronometer);

                notificationObject.SetColor(androidExtension.color);

                notificationObject.SetUseVibration(notificationObject.useVibration);
                notificationObject.SetVibrationPattern(androidExtension.vibrationPattern);

                notificationObject.SetUseLights(androidExtension.useLights);
                notificationObject.SetLightsColor(androidExtension.lightsColor);
                notificationObject.SetLightsOn(androidExtension.lightsOn);
                notificationObject.SetLightsOff(androidExtension.lightsOff);

                notificationObject.SetSmallIconResource(androidExtension.smallIconResource);
                notificationObject.SetLargeIconResource(androidExtension.largeIconResource);

                notificationObject.SetPerson(androidExtension.person);
            }

            if (repeatInterval > TimeSpan.Zero)
            {
                Android.LocalNotifications.LocalNotification.SendNotification
                    (id, when, notificationObject, cancelPrevious, (Android.LocalNotifications.LocalNotification.ScheduleMode)scheduleMode);
            }
            else
            {
                Android.LocalNotifications.LocalNotification.SendNotification
                    (id, when, repeatInterval, notificationObject, cancelPrevious, (Android.LocalNotifications.LocalNotification.ScheduleMode)scheduleMode);
            }
        }