Esempio n. 1
0
        /*public void SaveEvent()
         * {
         *  EKEvent newEvent = EKEvent.FromStore(eventStore);
         *  // set the alarm for 5 minutes from now
         *  newEvent.AddAlarm(EKAlarm.FromDate((NSDate)DateTime.Now.AddMinutes(1)));
         *  // make the event start 10 minutes from now and last 30 minutes
         *  newEvent.StartDate = (NSDate)DateTime.Now.AddMinutes(4);
         *  newEvent.EndDate = (NSDate)DateTime.Now.AddMinutes(8);
         *  newEvent.Title = "Appt. to do something Awesome!";
         *  newEvent.Notes = "Find a boulder, climb it. Find a river, swim it. Find an ocean, dive it.";
         *  newEvent.Calendar = eventStore.DefaultCalendarForNewEvents;
         *
         *  // save the event
         *  NSError e;
         *  eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
         *  if (e != null)
         *  {
         *      new UIAlertView("Err Saving Event", e.ToString(), null, "ok", null).Show();
         *      return;
         *  }
         *  else
         *  {
         *      new UIAlertView("Event Saved", "Event ID: " + newEvent.EventIdentifier, null, "ok", null).Show();
         *      Console.WriteLine("Event Saved, ID: " + newEvent.EventIdentifier);
         *  }
         *
         *  // to retrieve the event you can call
         *  EKEvent mySavedEvent = eventStore.EventFromIdentifier(newEvent.EventIdentifier);
         *  Console.WriteLine("Retrieved Saved Event: " + mySavedEvent.Title);
         *  /-*
         *  // to delete, note that once you remove the event, the reference will be null, so
         *  // if you try to access it you'll get a null reference error.
         *  eventStore.RemoveEvent(mySavedEvent, EKSpan.ThisEvent, true, out e);
         *  Console.WriteLine("Event Deleted.");*-/
         *
         * }*/

        public void CreateReminder()
        {
            EKReminder reminder = EKReminder.Create(eventStore);

            reminder.Title    = "first reminder";
            reminder.Calendar = eventStore.DefaultCalendarForNewReminders;
            NSError e;

            eventStore.SaveReminder(reminder, true, out e);
            if (e != null)
            {
                new UIAlertView("err saving reminder", e.ToString(), null, "ok", null).Show();
                return;
            }
            else
            {
                new UIAlertView("reminder saved", "ID: " + reminder.CalendarItemIdentifier, null, "ok", null).Show();
            }

            /*
             * //to retrieve the reminders
             * EKCalendarItem myReminder = eventStore.GetCalendarItem(reminder.CalendarItemIdentifier);
             * Console.WriteLine("Retrieved Saved Reminder: " + myReminder.Title);
             *
             * //to delete the reminders
             * eventStore.RemoveReminder(myReminder as EKReminder, true, out e);
             * Console.WriteLine("Reminder Deleted.");*/
        }
Esempio n. 2
0
        public void Predicates()
        {
            if (Runtime.Arch == Arch.DEVICE)
            {
                Assert.Inconclusive("defaults are different on devices");
            }

            var store = new EKEventStore(EKEntityMask.Reminder);
            var rem   = EKReminder.Create(store);

            rem.Calendar = store.DefaultCalendarForNewReminders;

            NSError error;

            Assert.IsTrue(store.SaveReminder(rem, true, out error), "SaveReminder");

            var  predicate = store.PredicateForIncompleteReminders(null, null, new [] { rem.Calendar });
            var  mre       = new ManualResetEvent(false);
            bool found     = false;

            store.FetchReminders(predicate, l => {
                found = l.Any(ll => ll.ClassHandle == rem.ClassHandle);
                mre.Set();
            });

            Assert.IsTrue(mre.WaitOne(3000), "#1");
            Assert.IsTrue(found, "#2");

            mre.Reset();
            predicate = store.PredicateForReminders(null);

            store.FetchReminders(predicate, l => mre.Set());
            Assert.IsTrue(mre.WaitOne(3000), "#10");

            mre.Reset();
            predicate = store.PredicateForCompleteReminders(null, null, null);

            store.FetchReminders(predicate, l => mre.Set());
            Assert.IsTrue(mre.WaitOne(3000), "#20");

            Assert.IsTrue(store.RemoveReminder(rem, true, out error), "RemoveReminder");
        }
Esempio n. 3
0
        public async Task AddReminder(string title, string notes, DateTime date)
        {
            try
            {
                var result = await _eventStore.RequestAccessAsync(EKEntityType.Reminder);

                if (result.Item1)
                {
                    EKReminder reminder = null;
                    var        predicat = _eventStore.PredicateForReminders(null);

                    var reminders = await _eventStore.FetchRemindersAsync(predicat);

                    reminder = reminders.Where((EKReminder arg) => !arg.Completed && arg.Title == title).FirstOrDefault();

                    if (reminder == null)
                    {
                        reminder = EKReminder.Create(_eventStore);
                    }

                    reminder.Title = title;
                    EKAlarm timeToRing = new EKAlarm();
                    timeToRing.AbsoluteDate = ConvertDateTimeToNSDate(date);
                    reminder.AddAlarm(timeToRing);
                    reminder.Calendar = _eventStore.DefaultCalendarForNewReminders;
                    reminder.Notes    = notes;
                    NSError error;
                    _eventStore.SaveReminder(reminder, true, out error);

                    if (error != null)
                    {
                        Debug.WriteLine(error.Description);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }