【发布时间】:2015-05-06 18:41:50
【问题描述】:
我正在尝试在
中添加日历事件-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
基于为创建日历事件而收到的一些数据应用程序。
我的问题是: 创建日历事件的代码运行没有任何问题,但是 事件 没有显示在日历上。当我在执行“添加事件”代码后将应用程序带回前台时,我可以看到按主页按钮时添加的日历事件
此外,如果我的代码在应用程序处于后台时运行 2-3 次,则似乎事件条目在代码执行后仍处于“待定”状态,而当应用程序进入前台时,所有事件都会立即添加。
我所要做的就是将应用程序置于前台一次,然后再次按下主页按钮 - 现在我可以看到所有待处理的日历条目,一旦代码执行了一段时间,这些条目就应该添加。
这是已知的行为吗?任何人都可以建议不会导致应用商店拒绝的解决方法吗?
代码:
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if (error)
NSLog(@"EKEventStore error = %@", error);
if (granted)
{
NSLog(@"EKEvent *event ");
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = @"test";
event.startDate = [NSDate date];
event.endDate = [[NSDate date] dateByAddingTimeInterval:600];
[event setCalendar:[store defaultCalendarForNewEvents]];
NSError *err = nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
if (err)
{
NSLog(@"not added");
}
else
{
NSLog(@"successfully added");
}
}
}];
NSLog(@"background fetch");
}
【问题讨论】:
-
你用的是什么代码?
-
您是否调用了将数据添加到日历的权限
-
是的。该应用程序具有权限。也添加代码。
-
你要闹吗?