iphone - Monotouch EventKit - 无法检索 EventIdentifier

标签 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,和日历)

日历项没有 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;
        }

提前致谢!

最佳答案

当你去获取事件时,你必须这样做:

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

关于iphone - Monotouch EventKit - 无法检索 EventIdentifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15696959/

相关文章:

iphone - 计算加速度(驾驶汽车)

iphone - 将音频/视频流传输到HTTP服务器以外的iPhone

ios - 强制退出 iOS 应用程序后的重要位置更新

ios - 从 UIImage 获取 CurrentBackgroundImage 路径

c++ - 混合 monotuch 和 Obj-C 或 C++

iphone - 创建动态填充 NSMutableArrays 的 NSMutableDictionary

iphone - "Current location"文本应根据 iPhone 中的语言进行更改

objective-c - CG Gradient 在模拟器上运行,但不能在 iPhone 上运行

ios - 使用标签栏 Controller 和导航 Controller

c# - 尝试访问 WCF 服务时出现最新的 MonoTouch 4.0 问题