Kyl*_*uth 8 iphone cocoa-touch objective-c ios ekeventkit
我在我的应用程序中使用EKEventStore.我抓住默认商店并注册,以便在EKEventStoreChangedNotification对日历进行更改时收到通知.但是,当进行更改时,通知的发件人会被调用几次(5-10)次,有时在每次调用之间最多会有15秒.这会弄乱我的代码并使事情变得更加困难.我能做些什么吗?
谢谢
iOS7编辑:似乎就像iOS7的发布一样,这个问题已经消失了.现在,无论对CalendarStore所做的更改如何,只会EKEventStoreChangedNotification发送一个.
Tim*_*Tim 17
这是调度通知的确切方式以及每个实际通知的结果.根据我的经验,您可以期望收到至少一个项目更改通知(事件,提醒等),并至少再收到一个更改,以便对该项目的包含日历进行更改.
如果没有看到您的代码并知道正在做出哪些更改,我就无法对答案过于具体; 但是,一般来说,您有两种选择.
后一个解决方案是我的首选答案,可能看起来像(暂时忽略线程问题):
@property (strong) NSTimer *handlerTimer;
- (void)handleNotification:(NSNotification *)note {
// This is the function that gets called on EKEventStoreChangedNotifications
[self.handlerTimer invalidate];
self.handlerTimer = [NSTimer timerWithTimeInterval:2.0
target:self
selector:@selector(respond)
userInfo:nil
repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:self.handlerTimer
forMode:NSDefaultRunLoopMode];
}
- (void)respond {
[self.handlerTimer invalidate];
NSLog(@"Here's where you actually respond to the event changes");
}
Run Code Online (Sandbox Code Playgroud)