gpt4 book ai didi

ios11 - EKCalendarChooser 在 iOS11.1 上崩溃

转载 作者:行者123 更新时间:2023-12-04 01:49:30 27 4
gpt4 key购买 nike

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

感谢您的帮助。

最佳答案

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

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

关于ios11 - EKCalendarChooser 在 iOS11.1 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47048566/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com