iOS:打开具有已填充日期的“日历”应用“新事件”屏幕 [英] iOS: Open a Calendar app New Event screen with populated date
本文介绍了iOS:打开具有已填充日期的“日历”应用“新事件”屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过编程的方式将用户重定向到日历应用的新事件屏幕,其中包含开始日期和结束日期?我知道日历和提醒简介,但这似乎是过大了。我也尝试过 calshow://
,但似乎也没有用,或者我找不到正确的方案。
Is it possible to redirect a user to Calendar app New Event screen programmatically with populated start and end dates? I am aware of Introduction to Calendars and Reminders, but that seems to be an overkill. I have also tried calshow://
, but didn't seem to work either or I am couldn't find a correct scheme.
推荐答案
@import EventKit;
@import EventKitUI;
然后使用此事件包:
- (IBAction)ScheduleClicked:(id)sender {
EKEventStore *eventStore = [[EKEventStore alloc]init];
if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted,NSError* error){
if(!granted){
NSString *message = @"Hey! This Project Can't access your Calendar... check your privacy settings to let it in!";
dispatch_async(dispatch_get_main_queue(), ^{
// Present alert for warning.
});
}else{
EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];
addController.event = [self createEvent:eventStore];
addController.eventStore = eventStore;
[self presentViewController:addController animated:YES completion:nil];
addController.editViewDelegate = self;
}
}];
}
}
同时,还有一些代表提供结束日期的详细信息日历的开始日期。
Meanwhile there are some delegates for giving detail of end dates start date of calendar.
#pragma mark - eventEditDelegates -
- (void)eventEditViewController:(EKEventEditViewController *)controller didCompleteWithAction:(EKEventEditViewAction)action{
if (action ==EKEventEditViewActionCanceled) {
[self dismissViewControllerAnimated:YES completion:nil];
}
if (action==EKEventEditViewActionSaved) {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
#pragma mark - createEvent -
-(EKEvent*)createEvent:(EKEventStore*)eventStore{
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = @"New Event";
event.startDate = @"Your start date";
event.endDate = @"Your end date";
event.location=@"Location";
event.allDay = YES;
event.notes =@"Event description";
NSString* calendarName = @"Calendar";
EKCalendar* calendar;
EKSource* localSource;
for (EKSource *source in eventStore.sources){
if (source.sourceType == EKSourceTypeCalDAV &&
[source.title isEqualToString:@"iCloud"]){
localSource = source;
break;
}
}
if (localSource == nil){
for (EKSource *source in eventStore.sources){
if (source.sourceType == EKSourceTypeLocal){
localSource = source;
break;
}
}
}
calendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:eventStore];
calendar.source = localSource;
calendar.title = calendarName;
NSError* error;
[eventStore saveCalendar:calendar commit:YES error:&error];
return event;
}
此createEvent将创建新日历
This createEvent will create new calendar
让我知道是否还有其他问题。
Let me know if you have any more questions.
这篇关于iOS:打开具有已填充日期的“日历”应用“新事件”屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文