【问题标题】:Warning message in Organizer saving EKEvent保存 EKEvent 的管理器中的警告消息
【发布时间】:2014-08-11 16:51:33
【问题描述】:

当我创建一个事件时:

EKEvent *newEvent = [EKEvent eventWithEventStore:self.store];

newEvent.title = title;
newEvent.startDate = startDate;
newEvent.endDate = finishDate;
newEvent.location = location;
EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:hoursOffSet * 60 * 60];
[newEvent addAlarm:alarm];
newEvent.calendar = cal;


BOOL eventSaved = [self.store saveEvent:newEvent span:EKSpanFutureEvents commit:YES error:error];
NSLog(@"identifier %@",newEvent.eventIdentifier);
if (!eventSaved) {
    if(!cal)
    {
        *error = [NSError errorWithDomain:@"ASTEventStore" code:CALENDAR_NOT_FOUND_CODE_ERROR userInfo:NULL];
    }    
   NSLog(@"Event didn't save in calendar %@",errorSavingInCalendar);
}

它通常可以正常工作,但我发现有时它正在保存事件并且它没有出现任何错误,但是我在日历应用程序中看不到该事件,实际上我也看不到创建的日历.

当我将事件保存在设备中时,我总是以这种方式在 Organizer-> Console 中获取它的 ID: : 标识符/与newEvent.eventIdentifier相同的id/

你知道这个警告是什么意思吗?

////更新

好吧,我注意到当应用程序保存 EKEvent 并显示警告消息时,还会显示另一条消息:

:2014-08-12 10:32:28.153|17|0x178e6d500:区域监控不可用或未启用。触发器被忽略!

我也尝试过google,但我没有找到任何东西。

有什么想法吗?

谢谢:)

【问题讨论】:

    标签: ios7 ekevent


    【解决方案1】:

    好吧,我想我找到了解决方案,问题是当我创建日历时,我以错误的方式获取源:(来自:how do I create a new EKCalendar on iOS device?

        // find local source for example
        EKSource *localSource = nil;
        for (EKSource *source in self.store.sources)
        {
            if (source.sourceType == EKSourceTypeLocal)  // or another source type that supports
            {
                localSource = source;
                break;
            }
        }
        if (!localSource) {
        NSLog(@"Local source is not available");
            if (error) {
                  *error = [NSError errorWithDomain:@"ASTEventStore" code:CALENDAR_ACCOUNT_NOT_TYPE_LOCAL userInfo:NULL];
            }
        }
        else{
           cal = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:self.store];
           cal.title = @"Calendar";
           cal.source = self.store.defaultCalendarForNewEvents.source;
           cal.CGColor = [UIColor blueColor].CGColor;
    
           NSError *calendarError;
           BOOL calendarSaved = [self.store saveCalendar:cal commit:YES error:&calendarError];
           if (!calendarSaved) {
                NSLog(@"calendar didn't saved %@",calendarError);
           }
           NSLog(@"cal id = %@", cal.calendarIdentifier);
           //We save the calendar ID
           calendarId = cal.calendarIdentifier;
           [defaults setObject:calendarId forKey:@"calendarId"];
           BOOL saved = [defaults synchronize];
           if (!saved) {
                NSLog(@"CALENDAR_ID didn't saved");
            }
       }
    

    现在我从 defaultCalendarForNewEvents 获得:

        cal = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:self.store];
        cal.title = @"Calendar";
        cal.source = self.store.defaultCalendarForNewEvents.source;
        cal.CGColor = [UIColor blueColor].CGColor;
    
        NSError *calendarError;
        BOOL calendarSaved = [self.store saveCalendar:cal commit:YES error:&calendarError];
        if (!calendarSaved) {
            NSLog(@"calendar didn't saved %@",calendarError);
        }
        NSLog(@"cal id = %@", cal.calendarIdentifier);
    
        if (!saved) {
            NSLog(@"CALENDAR_ID didn't saved");
        }
    

    我测试过,它在 iOS7 中运行良好。

    我希望这对某人有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      • 1970-01-01
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多