我的应用程序是否可以以编程方式将事件(经用户许可)添加到 iphone 日历?
干杯
w://
它在 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());
}
}
解决此问题的横向思考方法是考虑创建一个 ICS 文件,然后创建一封电子邮件(可以通过编程方式完成),然后将其发送给用户或他们想要的任何人。这就是我在代码中解决此问题的方式。它的美妙之处在于它也不会让用户产生您的应用程序将管理日期的感觉,即如果他们更改了您的应用程序中的某些内容,您将立即取消并重新预订。
这在官方的 iPhone API 中是不可能的,所以我怀疑它是否可以通过单点触控。
SDK 无法直接实现。您可能会尝试让用户订阅从您的服务器发布的在线日历,然后将事件上传到该日历,但您可能会遇到各种同步问题。