【问题标题】:Error getting all calendars: Error Domain=EKCADErrorDomain Code=1013 "(null)" Swift 3获取所有日历时出错:Error Domain=EKCADErrorDomain Code=1013 "(null)" Swift 3
【发布时间】:2017-04-10 21:31:58
【问题描述】:

我有一个应用程序应该将日历列表加载到选择器视图中。它可以工作,但只有在应用程序崩溃并再次打开之后。我不确定为什么它在应用程序的初始打开时不起作用。

日历权限请求:

func requestCalendarPermissions() {
eventInstance.requestAccess(to: .event, completion: {(accessGranted: Bool, error: Error?) in

    if accessGranted == true {
        print("Access Has Been Granted")
        }
    else {
        print("Change Settings to Allow Access")
    }
    })
}

检查权限状态:

func checkStatus() {
let currentStatus = EKEventStore.authorizationStatus(for: EKEntityType.event)

if currentStatus == EKAuthorizationStatus.notDetermined {
    requestCalendarPermissions()
}
else if currentStatus == EKAuthorizationStatus.authorized {
    print("Access Has Been Granted")
}
else if (currentStatus == EKAuthorizationStatus.denied) || (currentStatus == EKAuthorizationStatus.restricted){
    print("Access Has Been Denied")
}
}

PickerView 代码:

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return calendars.count
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    return calendars[row].title
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    CalendarField.text = calendars[row].title
    calID = calendars[row].calendarIdentifier
}

出现此错误:

获取所有日历时出错:Error Domain=EKCADErrorDomain Code=1013 "(null)"

应用程序最终崩溃,因为它试图填充 pickerView 并且没有要填充的数据。我确实加载了日历。

但是,由于某种原因,在应用崩溃并重新打开后,这不会发生。

谢谢

[更新]

控制台输出:

2016-11-26 18:04:23.856 PTF[98143:2347570] 获取所有错误 日历:错误域 = EKCADErrorDomain 代码 = 1013“(空)”日历 已加载 2016-11-26 18:04:23.869 PTF [98143:2347569] 获取所有错误 日历:错误域 = EKCADErrorDomain 代码 = 1013“(空)”日历 已加载

已授予访问权限 2016-11-26 18:04:25.954 PTF[98143:2347569] 获取所有日历时出错:错误域 = EKCADErrorDomain 代码 = 1013 “(null)”日历已加载

2016-11-26 18:04:46.620 PTF[98143:2347522] * 终止应用程序由于 未捕获的异常 'NSRangeException',原因:'* -[NSArray0 objectAtIndex:]: 空 NSArray' 的索引 0 超出范围 *** 第一次抛出调用堆栈:( 0 CoreFoundation 0x000000010bb6634b __exceptionPreprocess + 171 1 libobjc.A.dylib
0x000000010b5c721e objc_exception_throw + 48 2 核心基础
0x000000010bb7dddd -[__NSArray0 objectAtIndex:] + 93 3
libswiftCore.dylib 0x000000010d95311d _TFV​​s12_ArrayBuffer19_getElementSlowPathfSiPs9AnyObject_ + 125 4 libswiftCore.dylib 0x000000010d953003 _TFV​​s12_ArrayBuffer10getElementfTSi20wasNativeTypeCheckedSb_x + 147 5 libswiftCore.dylib 0x000000010d963b8a _TFSag9subscriptFSix + 138 6 PTF 0x000000010af8df12 _TFC3PTF19MainScreenTableView10pickerViewfTCSo12UIPickerView12didSelectRowSi11inComponentSi_T_ + 226 7 PTF 0x000000010af8e10a _TToFC3PTF19MainScreenTableView10pickerViewfTCSo12UIPickerView12didSelectRowSi11inComponentSi_T_ + 74 8 UIKit 0x000000010c0d301d -[UIPickerView _sendSelectionChangedForComponent:notify:] + 104 9 UIKit 0x000000010c0d326e -[UIPickerView _sendSelectionChangedFromTable:notify:] + 370 10 UIKit 0x000000010c8a560d -[UIPickerTableView _scrollingFinished] + 187 11 UIKit 0x000000010c8a57fd -[UIPickerTableView scrollViewDidEndDecelerating:] + 30 12 UIKit 0x000000010c1df821 -[UIScrollView(UIScrollViewInternal) _scrollViewDidEndDeceleratingForDelegate] + 91 13 UIKit 0x000000010c1dc362 -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 316 14 UIKit 0x000000010c1dc5b9 -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 505 15 UIKit 0x000000010c1d4503 -[UIScrollView _smoothScrollWithUpdateTime:] + 3304 16 石英核心 0x0000000113fa3bd5 _ZN2CA7Display15DisplayLinkItem8dispatchEy + 57 17 QuartzCore 0x0000000113fa3a95 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 449 18 核心基础 0x000000010baf8964 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION
+ 20 19 核心基础 0x000000010baf85f3 __CFRunLoopDoTimer + 1075 20 CoreFoundation 0x000000010baf817a __CFRunLoopDoTimers + 250 21 CoreFoundation
0x000000010baeff01 __CFRunLoopRun + 2065 22 核心基础
0x000000010baef494 CFRunLoopRunSpecific + 420 23 图形服务
0x000000011124aa6f GSEventRunModal + 161 24 UIKit
0x000000010c0eff34 UIApplicationMain + 159 25 PTF
0x000000010af9f36f 主要 + 111 26 libdyld.dylib
0x000000010f30368d start + 1 ) libc++abi.dylib: 终止于 NSException 类型的未捕获异常

【问题讨论】:

  • 哪一行代码导致错误信息?为什么你的应用程序会崩溃?如果您的应用程序崩溃是因为您的应用程序无法访问日历,那么您需要修复您的代码。
  • 该应用程序可以访问日历,但在授予访问权限后,它应该允许用户单击文本字段并弹出一个带有日历列表的选择器视图。但是,在应用程序的初始安装时,列表为空,然后崩溃。在所述崩溃之后,可以重新打开应用程序,并且现在选择器视图中填充了日历列表。
  • 你没有回答我的任何问题。哪一行代码导致您发布的错误?哪一行代码导致您的崩溃?崩溃的错误信息是什么?如果您不想提供详细信息以供人们帮助您,何苦发布问题?
  • 我在崩溃前后添加了控制台输出。我发布的错误没有明确调用导致它的任何代码行。我假设导致崩溃的代码行是pickerview didselectrow,因为日历列表是空的。

标签: ios iphone swift compiler-errors calendar


【解决方案1】:

我刚刚遇到了这个问题。在“requestAccess”之后,文档说要在 eventInstance 上调用“reset”。然而,即使这样也没有让事情奏效。但是得到一个新的 eventInstance 确实如此。我正在使用目标 c,因此我释放了我正在使用的 EKEventStore 对象并分配了一个新对象。

【讨论】:

  • 这应该是公认的答案!也为我工作!
  • 这在 Objective-c 中也适用于我,而在我的商店实例上调用 -reset 并没有解决问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-27
  • 1970-01-01
  • 1970-01-01
  • 2018-05-13
  • 2015-10-29
  • 2021-04-15
相关资源
最近更新 更多