【问题标题】:EKCalendarChooser crashes on iOS11.1EKCalendarChooser 在 iOS11.1 上崩溃
【发布时间】:2017-11-01 05:06:24
【问题描述】:

我执行以下代码,让用户选择多个日历用于我的记事本应用程序。直到 iOS 10.3.1,都没有问题。在 11.0.2 上,它仍在实际设备上工作。但是,从 11.1 开始,它会因以下错误而崩溃。

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKeyedSubscript:]: key cannot be nil'

代码如下。基本上,我正在打开一个空白日历选择器。

if (_eventStore == nil) {
    _eventStore = [[EKEventStore alloc] init];
}
// the selector is available, so we must be on iOS 6 or newer
[_eventStore requestAccessToEntityType:EKEntityTypeEvent
                           completion:^(BOOL granted, NSError *error) {
                               dispatch_async(dispatch_get_main_queue(), ^{
                                   if (error)
                                   {
                                       // display error message here
                                   }
                                   else if (!granted)
                                   {
                                       // display access denied error message here
                                   }
                                   else
                                   {
                                       // access granted

                                       EKCalendarChooser *calendarChooser = [[EKCalendarChooser alloc]
                                                                             initWithSelectionStyle:EKCalendarChooserSelectionStyleMultiple
                                                                             displayStyle:EKCalendarChooserDisplayAllCalendars
                                                                             eventStore:_eventStore];

                                       calendarChooser.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
                                       calendarChooser.delegate = self;
                                       calendarChooser.showsCancelButton = YES;
                                       calendarChooser.showsDoneButton = YES;


                                           NSSet *calendarSet = [[NSSet alloc] init]; 
                                           calendarChooser.selectedCalendars = calendarSet;


                                       UINavigationController *sub = [[UINavigationController alloc] initWithRootViewController:calendarChooser];
                                       sub.navigationBar.barStyle = UIBarStyleDefault;
                                       sub.toolbar.barStyle = UIBarStyleDefault;
                                       [self presentViewController:sub animated:YES completion:nil];
                                       //ios11 crashes after this
                                   }
                               });
                           }];

感谢您的帮助。

【问题讨论】:

    标签: ios11 xcode9


    【解决方案1】:

    事实证明 EKCalendarChooserDisplayAllCalendars 导致了崩溃。虽然不是很理想,但现在iOS 11.1或更高版本时我可以避免崩溃。

                                           EKCalendarChooserDisplayStyle displayStyle = EKCalendarChooserDisplayAllCalendars;
                                           if (@available(iOS 11.1, *)) {
                                               displayStyle = EKCalendarChooserDisplayWritableCalendarsOnly;
                                           }
                                           EKCalendarChooser *calendarChooser = [[EKCalendarChooser alloc]
                                                                                 initWithSelectionStyle:EKCalendarChooserSelectionStyleMultiple
                                                                                 displayStyle:displayStyle
                                                                                 eventStore:eventStore]; 
    

    【讨论】:

    • 遇到了同样的问题。如果我只能访问可写日历,那就太糟糕了。
    • 是的,绝对可怕。至少苹果承认存在问题。 (从 EventKit 初始化 EKCalendarChooser 可能会导致应用崩溃。(34608102))developer.apple.com/library/content/releasenotes/General/…
    • 这个周末我发现了另一个错误。如果您在秋季时间更改期间保存开始和结束时间在 1AM 和 2AM 之间的 EKEvent,如果时间是 1AM 到 2AM 的第二次出现,则数据库减去一个小时到结束时间(但不是开始时间),导致事件在结束后开始。我提交了一个错误报告,但我很好奇是否有其他人可以复制这个错误。请注意,您需要查询原始日期,因为这两个日期将使用区域设置日期格式进行相同的格式化。
    • 我很好奇你的发现。你能把它作为一个新问题发布并告诉我它的 URL 吗?谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-10
    • 2018-11-01
    • 1970-01-01
    • 2011-07-24
    • 2011-09-18
    • 2016-06-02
    相关资源
    最近更新 更多