我正在使用iPhone应用程序。
如何将新事件与iOS日历同步?
答案 0 :(得分:7)
你可以通过这个github代码,如果你想在你的应用程序的calander中同步事件,这将真正帮助你...
https://github.com/klazuka/Kal
希望这能解决你的问题...
另一个: -
为了实现压延并与calander数据同步,你必须通过在代码中添加Event Frame工作来实现压缩: -
EventKitUI.framework
EventKit.framework
在添加这些框架后添加这两个框架,你必须更新你的viewController,你必须在其中提供更新calander的选项或者calander的Alarm选项。
在.h文件中导入这两个
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>
EKEventEditViewDelegate协议,
制作这些类的对象
EKEventViewController *detailViewController;
EKEventStore *eventStore;
EKCalendar *defaultCalendar;
NSMutableArray *eventsList;
然后制作@property和@synthesize
在calander中为addEvents创建一个方法
-(IBAction) addEvent:(id)sender;
然后执行此操作转到.m文件
@synthesize属性。
你的viewDidLoad方法中的添加了以下内容: -
self.eventStore = [[EKEventStore alloc] init];
self.eventsList = [[NSMutableArray alloc] initWithArray:0];
// Get the default calendar from store.
self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];
// create an Add button
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bell.png" ] style:UIBarButtonItemStylePlain target:self action:@selector(addEvent:)];
//UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(addEvent:)];
self.navigationItem.rightBarButtonItem = addButtonItem;
[addButtonItem release];
and added this...
#pragma mark -
#pragma mark Add a new Event
-(IBAction) addEvent:(id)sender {
self.eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
// event.title =@"Whatever you want your title to be";
event.title = self.currentTitle;
// NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
event.allDay = YES;
EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];
addController.event = event;
addController.eventStore = self.eventStore;
[self presentModalViewController:addController animated:YES];
addController.editViewDelegate = self;
[addController release];
}
#pragma mark -
#pragma mark EKEventEditViewDelegate
// 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;
}
现在我认为您了解代码...... 感谢....