创建EKCalendar IOS Objective-C

时间:2016-08-31 16:00:42

标签: ios objective-c calendar eventkit ekeventkit

我使用EventKit来创建EKCalendar。 我尝试使用此方法创建它。当我在模拟器中测试时,日历创建(截图)并显示在默认日历中,但是当我在设备上执行相同操作时它没有工作,没有错误,所有相同但没有结果。 enter image description here

-(void)createCalendar{
    EKEventStore *eventStore = [[EKEventStore alloc] init];
    EKCalendar *calendar = [EKCalendar    calendarForEntityType:EKEntityTypeEvent eventStore:eventStore];
calendar.title = @"my calendarik";

// Iterate over all sources in the event store and look for the local source
EKSource *theSource = nil;
for (EKSource *source in eventStore.sources) {
    if (source.sourceType == EKSourceTypeLocal) {
        theSource = source;
        break;
    }
}
NSString    *iden = calendar.calendarIdentifier;

if (theSource) {
    calendar.source = theSource;
} else {
    NSLog(@"Error: Local source not available");
    return;
}

NSError *error = nil;
BOOL result = [eventStore saveCalendar:calendar commit:YES error:&error];
if (result) {
    NSLog(@"Saved calendar to event store.");

} else {
    NSLog(@"Error saving calendar: %@.", error);
}
   EKCalendar* calendar_;


    NSArray *allCalendars = [eventStore calendarsForEntityType:EKEntityTypeEvent];
    for (EKCalendar *cal in allCalendars) {
    if ([cal.calendarIdentifier isEqualToString:iden]) {
                        calendar_ = cal;
                           break;

            }

else {
        calendar_ = [eventStore calendarWithIdentifier:iden];
    }
   }

`

0 个答案:

没有答案