我对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);
但是我怎么能编辑事件,因为它现在变得重复了。
答案 0 :(得分:1)
如果您知道正确的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文档包含更多使用日历的示例。