我有一個應用程序,應該將日曆列表加載到pickerview。它的作品,但只有在應用程序崩潰後再次打開。我不確定爲什麼它不適用於應用程序的初始打開。獲取所有日曆時出錯:錯誤域= EKCADErrorDomain代碼= 1013「(空)」Swift 3
日曆權限請求:
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
}
此錯誤出現:
錯誤獲取所有日曆:錯誤域= EKCADErrorDomain代碼= 1013「(空)」
該應用程序崩潰,最後,因爲它試圖填補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 「(空)」 日曆加載
2016 -11-26 18:04:46.620 PTF [98143:2347522] *終止應用程序由於 未捕獲的異常 'NSRangeException',原因: '* - [NSArray0 objectAtIndex:]:索引0超出界限爲空的NSArray' *** First throw call stack :(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 _sendSelectionChangedForComponent:通知:] + 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核心基礎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 start + 1)libC++ abi.dylib:終止於 未捕獲的異常類型NSException
哪一行代碼導致錯誤消息?爲什麼你的應用程序崩潰?如果您的應用崩潰了,因爲您的應用無法訪問日曆,那麼您需要修復代碼。 – rmaddy
該應用程序可以訪問日曆,但訪問後,它應該允許用戶單擊文本框和pickerview與日曆列表彈出。但是,在應用程序的初始安裝時,列表爲空,然後崩潰。在發生崩潰後,應用程序可以重新打開,pickerview現在會填充日曆列表。 – rutheferd
你沒有回答我的任何問題。哪行代碼導致您發佈的錯誤?哪一行代碼導致你的崩潰?什麼是從崩潰錯誤信息?如果您不希望提供詳細信息讓人們來幫助您,那麼爲什麼還要張貼這個問題呢? – rmaddy