EKEventStoreChangedNotification未触发 [英] EKEventStoreChangedNotification not firing
问题描述
所以我正在玩EventKit并且在我在原生日历应用程序中添加/修改/删除日历条目时尝试触发EKEventStoreChangedNotification,但在获得访问日历的权限后,确认我是授权并注册通知
So I'm currently playing around with EventKit and was trying to get the EKEventStoreChangedNotification to fire when I add/modify/delete calendar entries in the native Calendar app, but after asking permission to access the Calendar, confirming that I'm authorized and signing up for the notification with
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(storeChanged:)
name:EKEventStoreChangedNotification
object:nil];
永远不会调用选择器。还尝试了块语法,它也不起作用。
the selector is never called. Also tried the block syntax, which doesn't work either.
所以我认为我做错了,发现这个示例代码,据说有工作通知,但即使在拉动该项目并确保调用addObserver行之后,我也无法在修改日历时看到调用选择器。
So I figured I'm doing something wrong and found this sample code, which supposedly has working notifications, but even after pulling that project and making sure that the addObserver line is getting called, I haven't been able to see the selector being called when I modify the calendar.
任何想法如何进一步调试?
Any ideas how to debug this further?
推荐答案
确保您的 EKEventStore
未被取消分配。例如,将其分配给一个强大的属性。
Make sure your EKEventStore
isn't being deallocated. For example, assign it to a strong property.
以下应用程序在库存日历应用程序中进行编辑时记录一个字符串:
The following app logs a string when an edit is made in the stock Calendar app:
#import <EventKit/EventKit.h>
@interface AppDelegate : UIResponder<UIApplicationDelegate>
@property (strong, nonatomic) EKEventStore *eventStore;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.eventStore = [[EKEventStore alloc] init];
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventStoreChangedNotification:) name:EKEventStoreChangedNotification object:nil];
}
}];
return YES;
}
- (void)eventStoreChangedNotification:(NSNotification *)notification {
NSLog(@"Event store changed");
}
@end
这篇关于EKEventStoreChangedNotification未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!