[英]iOS: Open a Calendar app New Event screen with populated date
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. 我也尝试过
calshow://
,但是似乎也没有用,或者我找不到正确的方案。
@import EventKit;
@import EventKitUI;
then present eventkit using this: 然后使用以下代码显示eventkit:
- (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;
}
This createEvent will create new calendar 此createEvent将创建新的日历
Let me know if you have any more questions. 如果您还有其他问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.