Monotouch EventKit - 无法检索EventIdentifier

时间:2013-03-29 03:41:50

标签: iphone ios xamarin.ios eventkit

我正在使用此处的示例:http://docs.xamarin.com/guides/ios/platform_features/introduction_to_eventkit#4.3.creating-an-event-programmatically

我问过Xamarin,他们说我应该使用EventIdentifier而不是CalendarItemIdentifier - 但是,当你按照他们说的方式查找事件时(startDate,endDate和Calendar)

日历项目没有EventIdentifier属性,我不知道如何投射或我应该在那里做什么。

这是我正在做的一个基本的例子。问题是,当我按标识符查找事件时,它不存在,因为它是CalendarItemIdentifier而不是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;
        }

提前致谢!

1 个答案:

答案 0 :(得分:1)

当你去参加活动时,你必须这样做:

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