简体   繁体   English

添加事件屏幕未在iOS中打开

[英]Add event screen is not opening in iOS

In my iOS app I want to create event in calendar and I've found code but the code directly creates an event instead of opening Add event screen. 在我的iOS应用中,我想在日历中创建事件,并且找到了代码,但是代码直接创建了一个事件,而不是打开“添加事件”屏幕。 I want to allow user to set reminder through add event screen. 我想允许用户通过添加事件屏幕设置提醒。

My Code is Below : 我的代码如下:

EKEventStore *es = [[EKEventStore alloc] init];
EKAuthorizationStatus authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
BOOL needsToRequestAccessToEventStore = (authorizationStatus == EKAuthorizationStatusNotDetermined);

if (needsToRequestAccessToEventStore) {
    [es requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        if (granted) {
            EKEvent *event = [EKEvent eventWithEventStore:es];
            event.title = @"Event Title";
            event.startDate = [NSDate date]; // today
            event.endDate = [event.startDate dateByAddingTimeInterval:60*60];  // Duration 1 hr
            [event setCalendar:[es defaultCalendarForNewEvents]];
            NSError *err = nil;
            [es saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
              NSLog(@"Error : %@", err);
        } else {
            // Denied
        }
    }];
} else {
    BOOL granted = (authorizationStatus == EKAuthorizationStatusAuthorized);
    if (granted) {
        EKEvent *event = [EKEvent eventWithEventStore:es];
        event.title = @"Event Title";
        event.startDate = [NSDate date]; // today
        event.endDate = [[NSDate date] dateByAddingTimeInterval:60*60];  // Duration 1 hr
        [event setCalendar:[es defaultCalendarForNewEvents]];
        NSError *err = nil;
        [es saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
        NSLog(@"Error : %@", err);
    } else {
        // Denied
    }
}

Based in the EKEventStore documentation, the method: [es saveEvent:event span:EKSpanThisEvent commit:YES error:&err]; 基于EKEventStore文档,该方法: [es saveEvent:event span:EKSpanThisEvent commit:YES error:&err]; is saving the event. 正在保存事件。 Your code is working correctly and this code should not open the "Add event screen" as you are expecting. 您的代码正常工作,并且该代码不会像您期望的那样打开“添加事件屏幕”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM