1

I am using the example found here : http://docs.xamarin.com/guides/ios/platform_features/introduction_to_eventkit#4.3.creating-an-event-programmatically

I asked Xamarin and they said I was supposed to use EventIdentifier instead of CalendarItemIdentifier - However, when you look up an event the way they say (startDate, endDate, and Calendar)

Calendar items don't have an EventIdentifierproperty, and I'm not sure how to cast that or what I'm supposed to do there.

Here's a basic example of what I am doing. The problem is that when I go to look up an event by the identifier it doesn't exist since it's a CalendarItemIdentifier instead of an EventIdentifier

public string CreateDefaultEvent ()
        {
            // Creating an event for demonstration purposes
            // This is the sample code from your website to create an event programmatically
            EKEvent newEvent = EKEvent.FromStore ( Application.AppEventStore );
            // set the alarm for 10 minutes from now
            newEvent.AddAlarm ( EKAlarm.FromDate ( DateTime.Now.AddMinutes ( 10 ) ) );
            // make the event start 20 minutes from now and last 30 minutes
            newEvent.StartDate = DateTime.Now.AddMinutes ( 20 );
            newEvent.EndDate = DateTime.Now.AddMinutes ( 50 );
            newEvent.Title = "Get outside and do some exercise!";
            newEvent.Notes = "This is your motivational event to go and do 30 minutes of exercise. Super important. Do this.";
            newEvent.Calendar = Application.AppEventStore.DefaultCalendarForNewEvents;

            NSError e;
            Application.AppEventStore.SaveEvent ( newEvent, EKSpan.ThisEvent, out e );
            Console.WriteLine ("Event Saved, ID: " + newEvent.CalendarItemIdentifier);
            return newEvent.CalendarItemIdentifier;
        }

        public string RetrieveCreatedEvent (string _eventIdentifier)
        {
            // We will just return the event's notes to see if we got a valid event
            EKEvent savedEvent = Application.AppEventStore.EventFromIdentifier (_eventIdentifier);
            return savedEvent.Notes;
        }

Thanks in advance!

4

1 回答 1

1

When you go to get the event you have to do this:

NSPredicate query = Util.MyEventStore.PredicateForEvents (Util.DateTimeToNSDate(startDate), Util.DateTimeToNSDate(endDate), null);
//EKCalendarItem[] eventArrary = Util.MyEventStore.EventsMatching (query);
EKEvent[] eventArrary = Util.MyEventStore.EventsMatching (query);

我不知道为什么我最初把它变成了一个EKCalendarItem[]但是,你必须使用一个EKEvent

于 2013-03-29T04:36:34.523 回答