【问题标题】:iOS: Open a Calendar app New Event screen with populated dateiOS:打开带有填充日期的日历应用新事件屏幕
【发布时间】:2016-11-10 10:24:11
【问题描述】:

是否可以使用填充的开始日期和结束日期以编程方式将用户重定向到日历应用“新事件”屏幕?我知道Introduction to Calendars and Reminders,但这似乎有点矫枉过正。我也试过calshow://,但似乎也没有用,或者我找不到正确的方案。

【问题讨论】:

  • 是的,这可能发生,您可以重定向它。
  • @NarendraPandey 你介意详细说明一下吗?

标签: ios objective-c iphone swift calendar


【解决方案1】:
@import EventKit;
@import EventKitUI;

然后使用这个来展示 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;
            }
    }];
  }
}

同时有一些代表提供日历的结束日期开始日期的详细信息。

#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 将创建新日历

如果您还有其他问题,请告诉我。

【讨论】:

  • 我说我不关心以编程方式创建事件,只关心使用预先填充的值重定向到日历应用新事件屏幕
  • 您可以重定向作为您的事件屏幕的 EKEventEditViewController
  • 和我做的同样的事情检查上面的代码。您可以在此代表中使用预先填充的值进入事件屏幕 -(EKEvent*)createEvent:(EKEventStore*)eventStore{
  • 我一头雾水,那你代码为什么叫eventStore saveCalendar:calendar commit:YES
  • 基本上你必须创建日历。如果你没有,那么你可以使用你的默认日历。顺便说一句,如果你想要你的项目日历,那么你可以这样做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 1970-01-01
相关资源
最近更新 更多