Esempio n. 1
0
        /// <summary>
        /// Creates a scheduled toast notification with the required values.
        /// </summary>
        /// <param name="content">Text content.</param>
        /// <param name="title">Toast title.</param>
        /// <param name="deliveryTime">When to display the toast.</param>
        /// <returns></returns>
        public static ScheduledToastNotification CreateScheduledToastNotification(string content, string title, DateTimeOffset deliveryTime)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            XmlDocument doc          = Windows.UI.Notifications.ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            var         textElements = doc.GetElementsByTagName("text");
            textElements[0].InnerText = title;
            textElements[1].InnerText = content;
            return(new ScheduledToastNotification(new Windows.UI.Notifications.ScheduledToastNotification(doc, deliveryTime)));
#elif WINDOWS_PHONE
            throw new PlatformNotSupportedException();
#elif __ANDROID__
            throw new PlatformNotSupportedException();
#elif __MAC__
            NSUserNotification notification = new NSUserNotification();
            notification.Title           = title;
            notification.InformativeText = content;
            notification.SoundName       = NSUserNotification.NSUserNotificationDefaultSoundName;
            notification.DeliveryDate    = deliveryTime.ToNSDate();
            return(notification);
#elif __UNIFIED__
            UNMutableNotificationContent notificationContent = new UNMutableNotificationContent();
            notificationContent.Title = title;
            notificationContent.Body  = content;
            notificationContent.Sound = UNNotificationSound.Default;
            NSDateComponents dc = NSCalendar.CurrentCalendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, deliveryTime.ToNSDate());
            UNCalendarNotificationTrigger trigger = UNCalendarNotificationTrigger.CreateTrigger(dc, false);

            return(new ScheduledToastNotification(notificationContent, trigger));
#else
            return(new ScheduledToastNotification(content, title, deliveryTime));
#endif
        }
        protected override IEnumerable <CalendarItem> NativeGetEventsInRange(DateTimeOffset start, DateTimeOffset end)
        {
            var calendars = eventStore.GetCalendars(EKEntityType.Event);

            var predicate = eventStore
                            .PredicateForEvents(start.ToNSDate(), end.ToNSDate(), calendars);

            var calendarItems = eventStore
                                .EventsMatching(predicate)
                                ?.Where(isValidEvent)
                                ?.Select(calendarItemFromEvent)
                                ?? new CalendarItem[0];

            return(calendarItems);
        }
        /// <summary>
        /// Creates a scheduled toast notification with the required values.
        /// </summary>
        /// <param name="content">Text content.</param>
        /// <param name="title">Toast title.</param>
        /// <param name="deliveryTime">When to display the toast.</param>
        /// <returns></returns>
        public static ScheduledToastNotification CreateScheduledToastNotification(string content, string title, DateTimeOffset deliveryTime)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            XmlDocument doc = Windows.UI.Notifications.ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            var textElements = doc.GetElementsByTagName("text");
            textElements[0].InnerText = title;
            textElements[1].InnerText = content;
            return new ScheduledToastNotification(new Windows.UI.Notifications.ScheduledToastNotification(doc, deliveryTime));
#elif WINDOWS_PHONE
            throw new PlatformNotSupportedException();
#elif __ANDROID__
            throw new PlatformNotSupportedException();
#elif __IOS__
            UILocalNotification localNotification = new UILocalNotification();
            localNotification.AlertTitle = title;
            localNotification.AlertBody = content;
            localNotification.FireDate = deliveryTime.ToNSDate();
            localNotification.SoundName = UILocalNotification.DefaultSoundName;
            localNotification.RepeatCalendar = global::Foundation.NSCalendar.CurrentCalendar;
            localNotification.RepeatInterval = global::Foundation.NSCalendarUnit.Minute;

            return new ScheduledToastNotification(localNotification);
#else
            return new ScheduledToastNotification(content, title, deliveryTime);
#endif
        }