繁体   English   中英

Xamarin.Forms iOS编辑日历事件

[英]Xamarin.Forms ios edit calendar event

我对iOS中的日历有疑问,我可以使用以下代码在默认日历中创建一个事件:在用户授予访问权限但不显示该代码不重要之后,ofc

EKEventStore eventStore = new EKEventStore();

var StartDate = GSDFuncties.ToDateString(day, month, year);

//Insert the data into the agenda.
EKEvent newEvent = EKEvent.FromStore(eventStore);
newEvent.StartDate = DateTimeToNSDate(new DateTime(year, month, day));
newEvent.EndDate = DateTimeToNSDate(new DateTime(year, month, day).AddDays(1D));
newEvent.Title = title;
newEvent.Notes = description;
newEvent.Calendar = eventStore.DefaultCalendarForNewEvents;
eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, true, out e);

但是,自从事件被复制以来,我该如何编辑事件。

如果知道正确的EventID,则可以检索它,更新它的属性,然后再次保存:

// load an event by ID
EKEvent event = App.Current.EventStore.EventFromIdentifier (ID);

如果您不知道ID,可以编写查询来查找它:

NSPredicate query = App.Current.EventStore.PredicateForEvents ( startDate, endDate, null );

// execute the query
EKCalendarItem[] events = App.Current.EventStore.EventsMatching ( query );

然后,您需要浏览匹配的事件以找到所需的特定事件并进行更新。

Xamarin的EventKit文档包含更多使用日历的示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM