简体   繁体   English

iOS:打开具有已填充日期的“日历”应用“新事件”屏幕

[英]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.

相关问题 UITableViewController作为数据输入屏幕(iOS,Swift)和日历应用程序“ New Event”屏幕 - UITableViewController as data entry screen (iOS, Swift) a la Calendar app “New Event” screen 是否可以使用来自应用程序的预填充数据打开IOS日历应用程序的添加事件到日历屏幕? - Can I open the the add event to calendar screen of the IOS calendar app with pre-filled data from my app? 在锁定屏幕中使用“打开”命令打开应用程序(iOS 8) - Open app with “open”-command in locked screen (iOS 8) 如何以编程方式打开具有预先填充状态的iOS Facebook应用程序? - How to programmatically open iOS Facebook app with pre-populated status? iOS应用程序打开屏幕到应用程序闪烁 - iOS app open screen to app flashes 在具有特定活动ID的日历应用中打开“活动详情” - Open “Event Details” in calendar app with specific event id 如何从iOS 6.1中的应用程序打开本机日历应用程序? - How to open native calendar app from our app in iOS 6.1? 屏幕解锁后ios打开应用 - ios open app after screen unlock 快速-如何在特定的日期和时间打开日历应用程序? - swift- how to open up calendar app at specific date and time? 如何从网站上的链接打开本机iOS应用程序(日历,笔记...)? - How to open native iOS app (calendar, notes…) from a link on website?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM