gpt4 book ai didi

iphone - 将事件添加到 iPhone 应用程序的 iCal 中

转载 作者:行者123 更新时间:2023-12-03 20:55:15 25 4
gpt4 key购买 nike

我的申请中有一个要求,当我预约某一天的医生时,该天应该添加到 iCal 中。它应该在该特定日期生成警报 View 。

所以,我不知道如何在 iCal 中添加事件。请给我一些答案。

情况是,我确实有一个包含该特定约会的“日期”和“注释”的字符串(NSString)。那么,如何将所有这些信息插入到 iCal 中。

代码:

- (NSArray *)fetchEventsForToday {

NSDate *startDate = [NSDate date];

// endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:86400];

// Create the predicate. Pass it the default calendar.
NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate
calendars:calendarArray];

// Fetch all events that match the predicate.
NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];

return events;
}


// Overriding EKEventEditViewDelegate method to update event store according to user actions.
- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action {

NSError *error = nil;
EKEvent *thisEvent = controller.event;

switch (action) {
case EKEventEditViewActionCanceled:
// Edit action canceled, do nothing.
break;

case EKEventEditViewActionSaved:
// When user hit "Done" button, save the newly created event to the event store,
// and reload table view.
// If the new event is being added to the default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList addObject:thisEvent];
}
[controller.eventStore saveEvent:controller.event span:EKSpanThisEvent error:&error];
[self.tableView reloadData];
break;

case EKEventEditViewActionDeleted:
// When deleting an event, remove the event from the event store,
// and reload table view.
// If deleting an event from the currenly default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList removeObject:thisEvent];
}
[controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&error];
[self.tableView reloadData];
break;

default:
break;
}
// Dismiss the modal view controller
[controller dismissModalViewControllerAnimated:YES];

}

// Set the calendar edited by EKEventEditViewController to our chosen calendar - the default calendar.
- (EKCalendar *)eventEditViewControllerDefaultCalendarForNewEvents:(EKEventEditViewController *)controller
{
EKCalendar *calendarForEdit = self.defaultCalendar;
return calendarForEdit;
}

我已经使用了这些函数和委托(delegate)方法。请告诉我,当用户收到提醒时,如何打开有关该事件的信息?

最佳答案

您需要EventKit framework 。您可以询问EKEventStore为其日历,然后使用这些日历创建一个谓词,让您 find events that match the criteria you're looking for 。或者您可以创建一个新的 EKEvent对象和 save it into the event store .

关于iphone - 将事件添加到 iPhone 应用程序的 iCal 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5684759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com