var allCals = _eventStore.calendarsForEntityType(EKEntityTypeEvent)var predicate:nspredicate! = _eventStore.predicateForEventsWithStartDate(yearsAgo,endDate:toAgo,calendars:allCals)_eventStore.enumerateEventsMatchingPredicate(predicate,usingBlock:{ (event:EKEvent!,stop:UnsafeMutablePointer<ObjCBool>) in if (event.Title != nil && event.calendar != nil && event.calendar.calendarIDentifIEr != nil && event.lastModifIEdDate != nil ){ if event.attendees != nil{ // < -- SOMETIMES LEADS TO CRASH!! //... } else{ // standalone //... } } //...... })// end block
完整堆栈跟踪:[线程崩溃异常]
Thread : Fatal Exception: NSinvalidargumentexception0 CoreFoundation 0x2917649f __exceptionPreprocess + 1261 libobjc.A.dylib 0x36970c8b objc_exception_throw + 382 CoreFoundation 0x29096291 -[__NSSetM addobject:] + 6083 EventKit 0x29b4eacf -[EKPersistentObject primitiveRelationValueForKey:] + 5024 Foundation 0x29dc1617 -[NSObject(NSkeyvalueCoding) valueForKey:] + 2025 EventKit 0x29b5afc5 -[EKObjectToManyRelation _loadedItems] + 1206 EventKit 0x29b5aef3 -[EKObjectToManyRelation _effectiveItems] + 1027 EventKit 0x29b5ae69 -[EKObjectToManyRelation items] + 208 EventKit 0x29b5d179 -[EKCalendarItem attendees] + 369 MyApp 0x000d8c78 _TTSf2n_n_n_n_n_d_i_n_n___TFFC8MyApp17WmBuildGroupsTask14doInBackgroundFS0_FT_T_U_FTGSqCSo7EKEvent_GVSs20UnsafeMutablePointerV10ObjectiveC8ObjCBool__T_ (WmBuildGroupsTask.swift:421)10 MyApp 0x000d3f3c _TPA__TTSf2n_n_n_n_n_d_i_n_n___TFFC8MyApp17WmBuildGroupsTask14doInBackgroundFS0_FT_T_U_FTGSqCSo7EKEvent_GVSs20UnsafeMutablePointerV10ObjectiveC8ObjCBool__T_ (WmBuildGroupsTask.swift)11 MyApp 0x000d96b8 reabstraction thunk helper from @callee_owned (@owned Swift.ImplicitlyUnwrappedOptional<ObjectiveC.EKEvent>,@uNowned Swift.UnsafeMutablePointer<ObjectiveC.ObjCBool>) -> (@uNowned ()) to @callee_uNowned @objc_block (@uNowned Swift.ImplicitlyUnwrappedOptional<ObjectiveC.EKEvent>,@uNowned Swift.UnsafeMutablePointer<ObjectiveC.ObjCBool>) -> (@uNowned ()) (WmBuildGroupsTask.swift)12 EventKit 0x29ba72a7 __60-[EKEventStore enumerateEventsMatchingPredicate:usingBlock:]_block_invoke + 13013 EventKit 0x29bad6af __41-[EKPredicateSearch startWithCompletion:]_block_invoke_2 + 69014 libdispatch.dylib 0x36ed07bb _dispatch_call_block_and_release + 1015 libdispatch.dylib 0x36ed9dab _dispatch_root_queue_drain + 86616 libdispatch.dylib 0x36edacd7 _dispatch_worker_thread3 + 9417 libsystem_pthread.dylib 0x37031e31 _pthread_wqthread + 66818 libsystem_pthread.dylib 0x37031b84 start_wqthread + 8
Thread : Crashed: com.apple.root.default-qos0 libsystem_kernel.dylib 0x36fb6dfc __pthread_kill + 81 libsystem_pthread.dylib 0x37034d37 pthread_kill + 622 libsystem_c.dylib 0x36f56909 abort + 763 libc++abi.dylib 0x362919c9 __cxa_bad_cast4 libc++abi.dylib 0x362ab671 default_unexpected_handler()5 libobjc.A.dylib 0x36970f25 _objc_terminate() + 1926 libc++abi.dylib 0x362a8de3 std::__terminate(voID (*)()) + 787 libc++abi.dylib 0x362a85a9 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code,_Unwind_Exception*)8 libobjc.A.dylib 0x36970d5f objc_exception_throw + 2509 CoreFoundation 0x29096291 -[__NSSetM addobject:] + 60810 EventKit 0x29b4eacf -[EKPersistentObject primitiveRelationValueForKey:] + 50211 Foundation 0x29dc1617 -[NSObject(NSkeyvalueCoding) valueForKey:] + 20212 EventKit 0x29b5afc5 -[EKObjectToManyRelation _loadedItems] + 12013 EventKit 0x29b5aef3 -[EKObjectToManyRelation _effectiveItems] + 10214 EventKit 0x29b5ae69 -[EKObjectToManyRelation items] + 2015 EventKit 0x29b5d179 -[EKCalendarItem attendees] + 3616 MyApp 0x000d8c78 _TTSf2n_n_n_n_n_d_i_n_n___TFFC8MyApp17WmBuildGroupsTask14doInBackgroundFS0_FT_T_U_FTGSqCSo7EKEvent_GVSs20UnsafeMutablePointerV10ObjectiveC8ObjCBool__T_ (WmBuildGroupsTask.swift:421)17 MyApp 0x000d3f3c _TPA__TTSf2n_n_n_n_n_d_i_n_n___TFFC8MyApp17WmBuildGroupsTask14doInBackgroundFS0_FT_T_U_FTGSqCSo7EKEvent_GVSs20UnsafeMutablePointerV10ObjectiveC8ObjCBool__T_ (WmBuildGroupsTask.swift)18 MyApp 0x000d96b8 reabstraction thunk helper from @callee_owned (@owned Swift.ImplicitlyUnwrappedOptional<ObjectiveC.EKEvent>,@uNowned Swift.UnsafeMutablePointer<ObjectiveC.ObjCBool>) -> (@uNowned ()) (WmBuildGroupsTask.swift)19 EventKit 0x29ba72a7 __60-[EKEventStore enumerateEventsMatchingPredicate:usingBlock:]_block_invoke + 13020 EventKit 0x29bad6af __41-[EKPredicateSearch startWithCompletion:]_block_invoke_2 + 69021 libdispatch.dylib 0x36ed07bb _dispatch_call_block_and_release + 1022 libdispatch.dylib 0x36ed9dab _dispatch_root_queue_drain + 86623 libdispatch.dylib 0x36edacd7 _dispatch_worker_thread3 + 9424 libsystem_pthread.dylib 0x37031e31 _pthread_wqthread + 668
第9行a.e. WmBuildGroupsTask.swift:421如果event.attendees!= nil {
任何人都可以散布如何摆脱这场崩溃,或至少使代码安全从崩溃?
[编辑1]
我也试过:
if event.hasAttendees { if let attArray:NSArray = event.attendees{ // crashes here /* ... */ }
}}
有趣的是,从命令行:po event.hasAttendees返回true
当po event.attendees返回null时。但还是崩溃了
[编辑2]
升级到Swift 1.2后,得到同样的崩溃(Crashlytics)。还试过:
if event.hasAttendees { if let attArray:[EKParticipant] = event.attendees as? [EKParticipant] // crash here { /* ... */ } }
有问题的事件是指像Google这样的日历,正如我上面提到的一样,99.5%的同一事件正常工作,并且我取得了与会者的成功。
我不是iOS大师,但看起来像它的内部iOS问题:
libobjc.A.dylib 0x36970d5f objc_exception_throw + 2509 CoreFoundation 0x29096291 -[__NSSetM addobject:] + 60810 EventKit 0x29b4eacf -[EKPersistentObject primitiveRelationValueForKey:] + 50211 Foundation 0x29dc1617 -[NSObject(NSkeyvalueCoding) valueForKey:] + 20212 EventKit 0x29b5afc5 -[EKObjectToManyRelation _loadedItems] + 12013 EventKit 0x29b5aef3 -[EKObjectToManyRelation _effectiveItems] + 10214 EventKit 0x29b5ae69 -[EKObjectToManyRelation items] + 2015 EventKit 0x29b5d179 -[EKCalendarItem attendees] + 36
谢谢,
很明显,这是iOS中的一个错误,所以你需要一个黑客去绕过它才能解决它。如果是Objective C,我将使用一个try catch块来尝试捕获异常,所以应用程序不会崩溃。
Here是在Swift中使用一个try块的例子,它使用Objective C实现:
总结以上是内存溢出为你收集整理的Swift iOS EKEventStore:从EKEvent获取参加者有时会与NSInvalidArgumentException全部内容,希望文章能够帮你解决Swift iOS EKEventStore:从EKEvent获取参加者有时会与NSInvalidArgumentException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)