EKEventStore with iOS小部件错误:[EventKit]客户端试图打开太多到calaccessd的连接。拒绝打开另一个

EKEventStore with iOS小部件错误:[EventKit]客户端试图打开太多到calaccessd的连接。拒绝打开另一个,ios,widget,ios13,ekeventstore,Ios,Widget,Ios13,Ekeventstore,我有一个iOS小部件,它使用EKEventStore处理提醒。小部件仅初始化EKEventStore一次,然后使用该实例。小部件通常在今天的viewController中查看时创建,在用户退出通知中心时销毁。这导致每次用户查看小部件时初始化EKEventStore。连续查看小部件10次后,出现以下错误: [EventKit] Client tried to open too many connections to calaccessd. Refusing to open another 我诊断

我有一个iOS小部件,它使用
EKEventStore
处理提醒。小部件仅初始化
EKEventStore
一次,然后使用该实例。小部件通常在今天的viewController中查看时创建,在用户退出通知中心时销毁。这导致每次用户查看小部件时初始化
EKEventStore
。连续查看小部件10次后,出现以下错误:

[EventKit] Client tried to open too many connections to calaccessd. Refusing to open another
我诊断了这个问题,发现它发生在小部件的10个视图之后。为了重现这一点,您需要打开另一个应用程序,然后每次都返回到小部件,以便在查看时重新加载小部件

我按如下方式正确初始化
EKEventStore

self.eventStore = [[EKEventStore alloc] init];
[self.eventStore requestAccessToEntityType:EKEntityTypeReminder
                                                   completion:^(BOOL granted, NSError *error) {

}];

我知道在小部件的同一会话中多次初始化
EKEventStore
可能会有问题。但是当用户离开小部件时,我希望当小部件从一开始重新加载时,初始化
EKEventStore
的有限次数会重置。

实现一个共享的单例类来管理
EKEventStore
,如下所示,在应用程序和扩展(小部件)中使用单例:

这就解决了上述问题。即使扩展或小部件被销毁,也会维护此单例。
感谢苹果公司提供此修复程序的支持。

我通过他们的代码级支持与苹果公司就此问题进行了联系。将在此处更新任何发现。
+(EventStoreManager *)sharedInstance {
    static dispatch_once_t onceToken;
    static EventStoreManager *  eventStoreSharedInstance;

    dispatch_once(&onceToken, ^{
        eventStoreSharedInstance = [[EventStoreManager alloc] init];
    });
    return eventStoreSharedInstance;
}