ios - EKEventStore 与 iOS Widget 错误 : [EventKit] Client tried to open too many connections to calaccessd. 拒绝打开另一个

标签 ios widget ios13 ekeventstore

我有一个 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) {

}];

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

最佳答案

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

+(EventStoreManager *)sharedInstance {
    static dispatch_once_t onceToken;
    static EventStoreManager *  eventStoreSharedInstance;

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

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

关于ios - EKEventStore 与 iOS Widget 错误 : [EventKit] Client tried to open too many connections to calaccessd. 拒绝打开另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58160810/

相关文章:

ios - 使用 UIKit Dynamics 将两个物体相互吸引

ios - 选择不是可以重命名的类型 Xcode 7

java - 是否有任何开源和免费的日历 UI 可重用组件?

javascript - 使用 $.widget 工厂覆盖 jQuery UI 自动完成选项

Android Widget Onclick 按钮或方法或来自另一个 Activity 的方法?

ios - UITableViewDiffableDataSource : how to get a section index

ios - 无法从 NSString 创建 NSUrl 总是得到 nil

IOS 在 subview 中绘制文本

ios - 如何使用dynamicProvider为暗模式创建初始化程序

ios - iOS 13,什么时候保存数据?