rut*_*erd 6 iphone calendar compiler-errors ios swift
我有一个应用程序,应该将日历列表加载到pickerview中.它可以工作,但只有在应用程序崩溃并再次打开之后.我不确定为什么它不适用于应用程序的初始打开.
日历权限请求:
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")
}
})
}
Run Code Online (Sandbox Code Playgroud)
检查权限状态:
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")
}
}
Run Code Online (Sandbox Code Playgroud)
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
}
Run Code Online (Sandbox Code Playgroud)
出现此错误:
获取所有日历时出错:错误域= EKCADErrorDomain代码= 1013"(null)"
该应用程序最终崩溃,因为它试图填充pickerView并且没有数据要填充.我加载日历.
但是,由于某些原因,在应用程序崩溃并重新打开后不会发生这种情况.
谢谢
[更新]
控制台出:
2016-11-26 18:04:23.856 PTF [98143:2347570]获取所有日历时出错:错误域= EKCADErrorDomain代码= 1013"(null)"日历已加载2016-11-26 18:04:23.869 PTF [98143:2347569获取所有日历时出错:错误域= EKCADErrorDomain代码= 1013"(null)"日历已加载
访问已被授予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:]:索引0超出空NSArray的界限'***First扔调用堆栈:(0的CoreFoundation 0x000000010bb6634b __exceptionPreprocess + 171 1 libobjc.A.dylib
0x000000010b5c721e objc_exception_throw + 48 2的CoreFoundation
0x000000010bb7dddd - [__ NSArray0 objectAtIndex:] + 93 3
libswiftCore.dylib 0x000000010d95311d _TFVs12_ArrayBuffer19_getElementSlowPathfSiPs9AnyObject_ + 125 4 libswiftCore.dylib 0x000000010d953003 _TFVs12_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 _sendSelecti onChangedForComponent:通知:] + 104 9的UIKit 0x000000010c0d326e - [UIPickerView _sendSelectionChangedFromTable:通知:] + 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:销:tramplingDragFlags:] + 505 15的UIKit 0x000000010c1d4503 - [UIScrollView中_smoothScrollWithUpdateTime:] + 3304 16 QuartzCore 0x0000000113fa3bd5 _ZN2CA7Display15DisplayLinkItem8dispatchEy + 57 17 QuartzCore 0x0000000113fa3a95 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 449 18 CoreFoundation 0x000000010baf8964 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 20 19 CoreFoundation 0x000000010baf85f3 __ CFRunLoopDoTimer + 1075 20的CoreFoundation 0x000000010baf817a __CFRunLoopDoTimers + 250 21的CoreFoundation
0x000000010baeff01 __CFRunLoopRun + 2065 22的CoreFoundation
0x000000010baef494 CFRunLoopRunSpecific + 420个23 GraphicsServices
0x000000011124aa6f GSEventRunModal + 161 24的UIKit
0x000000010c0eff34 UIApplicationMain + 159 25 PTF
0x000000010af9f36f主+ 111 26 libdyld.dylib
0x000000010f30368d启动+ 1)+的libc + abi.dylib:以NSException类型的未捕获异常终止
小智 13
我刚遇到这个问题.在'requestAccess'之后,文档说在eventInstance上调用'reset'.然而,即使这样也没有让事情发生.然而,获得一个新的eventInstance.我正在使用Objective c,所以我发布了我正在使用的EKEventStore对象并分配了一个新对象.
| 归档时间: |
|
| 查看次数: |
1478 次 |
| 最近记录: |