Monotouch - 从我的应用程序添加事件到iphone日历

2 iphone calendar xamarin.ios

我的应用程序是否可以以编程方式将事件(经用户许可)添加到iphone日历中?

干杯

女://

Chr*_*s S 5

它可以在iPhone 4 SDK中使用,所以在Monotouch中.看看EKEventStore和EKEvent.这是Apple文档.

以下是我保留的代码段页面中的示例:

public void CalendarEvents()
{
    EKEventStore store = new EKEventStore();
    EKCalendar calendar = store.DefaultCalendarForNewEvents;

    // Query the event
    if (calendar != null)
    {
        // Searches for every event in the next year
        NSPredicate predicate = store.PredicateForEvents(NSDate.Now,DateTime.Now.AddDays(360),new EKCalendar[] {calendar});

        store.EnumerateEvents(predicate, delegate(EKEvent currentEvent, ref bool stop)
        {
            // Perform your check for an event type
        });


        // Add a new event
        EKEvent newEvent = EKEvent.FromStore(store);
        newEvent.Title = "Lunch at McDonalds";
        newEvent.Calendar = calendar;
        newEvent.StartDate = DateTime.Now.Today;
        newEvent.EndDate = DateTime.Now.Today.AddDays(1);
        newEvent.Availability = EKEventAvailability.Free;
        store.SaveEvent(newEvent, EKSpan.ThisEvent, new IntPtr());
    }
}
Run Code Online (Sandbox Code Playgroud)