Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios EKEventStoreChangedNotification未启动_Ios_Iphone_Objective C_Eventkit - Fatal编程技术网

Ios EKEventStoreChangedNotification未启动

Ios EKEventStoreChangedNotification未启动,ios,iphone,objective-c,eventkit,Ios,Iphone,Objective C,Eventkit,因此,我目前正在使用EventKit,试图在我在本机日历应用程序中添加/修改/删除日历项时触发EKEventStoreChangedNotification,但在请求访问日历的权限、确认我已获得授权并使用注册通知后 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(storeChanged:)

因此,我目前正在使用EventKit,试图在我在本机日历应用程序中添加/修改/删除日历项时触发EKEventStoreChangedNotification,但在请求访问日历的权限、确认我已获得授权并使用注册通知后

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(storeChanged:)
                                             name:EKEventStoreChangedNotification
                                           object:nil];
永远不会调用选择器。还尝试了块语法,但也不起作用

所以我觉得我做错了什么,发现了这个,它应该有工作通知,但即使在拉动该项目并确保addObserver行被调用之后,我仍然无法看到在修改日历时调用选择器


你知道如何进一步调试吗?

我认为你需要添加eventStore作为对象。检查这个例子。对我有用

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(storeChanged:)
                                             name:EKEventStoreChangedNotification
                                           object:eventStore];
确保您的EKEventStore未被解除分配。例如,将其指定给强属性

在股票日历应用程序中进行编辑时,以下应用程序记录字符串:

#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
您必须确保EKEventStore对象保留在内存中以供使用

这些场景不适用于ARC:

@property (weak, nonatomic) EKEventStore *eventStore;
self.eventStore = [[EKEventStore alloc] init];
@property (strong, nonatomic) EKEventStore *eventStore;

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];
    }
}];

此场景适用于ARC:

@property (weak, nonatomic) EKEventStore *eventStore;
self.eventStore = [[EKEventStore alloc] init];
@property (strong, nonatomic) EKEventStore *eventStore;

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];
    }
}];

您是在模拟器中还是在设备上进行测试?@VahurRoosimaa能否请您指定您在何处提到上述代码以及如何进行测试?@VahurRoosimaa另外,您是否可以粘贴storeChanged:method的代码。它是否将通知对象作为参数?这不是必需的。也就是说,你应该指定对象,否则你会收到应用程序中每一个EKEventStore的通知,如果有多个EKEventStore,它可能会变慢…我有相同的问题,上面的解决方案都不适用于我。我也有这个问题。这对10.9版本的人有用吗?我在约塞米蒂10.10中尝试了相同的代码,效果很好,但在10.9中没有@拉姆沙德:你找到工作了吗?@ZS:确保你的EKEventStore没有被解除分配。这是唯一的诀窍