EKCalendarChooser在iOS11.1上崩溃

时间:2017-11-01 05:06:25

标签: ios11 xcode9

我执行以下代码让用户选择多个日历用于我的记事本应用。直到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
                                   }
                               });
                           }];

感谢您的帮助。

1 个答案:

答案 0 :(得分:4)

事实证明,EKCalendarChooserDisplayAllCalendars导致崩溃。虽然它并不理想,但现在我可以避免iOS为11.1或更高时的崩溃。

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