简体   繁体   English

Swift iOS EKEventStore:从EKEvent获取参与者有时会导致NSInvalidArgumentException崩溃

[英]Swift iOS EKEventStore : Fetching atendees from EKEvent causes sometimes to crash with NSInvalidArgumentException

I try to load all Calendar events by using block and sometimes (0.5% rate) I get NSInvalidArgumentException that causes to crash: 我尝试使用block加载所有日历事件, 有时 (0.5%率)我得到导致崩溃的NSInvalidArgumentException

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

Full stack trace: [thread crash + Exception] 完整堆栈跟踪:[线程崩溃+异常]

Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x2917649f __exceptionPreprocess + 126
1  libobjc.A.dylib                0x36970c8b objc_exception_throw + 38
2  CoreFoundation                 0x29096291 -[__NSSetM addObject:] + 608
3  EventKit                       0x29b4eacf -[EKPersistentObject primitiveRelationValueForKey:] + 502
4  Foundation                     0x29dc1617 -[NSObject(NSKeyValueCoding) valueForKey:] + 202
5  EventKit                       0x29b5afc5 -[EKObjectToManyRelation _loadedItems] + 120
6  EventKit                       0x29b5aef3 -[EKObjectToManyRelation _effectiveItems] + 102
7  EventKit                       0x29b5ae69 -[EKObjectToManyRelation items] + 20
8  EventKit                       0x29b5d179 -[EKCalendarItem attendees] + 36
9  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 + 130
13 EventKit                       0x29bad6af __41-[EKPredicateSearch startWithCompletion:]_block_invoke_2 + 690
14 libdispatch.dylib              0x36ed07bb _dispatch_call_block_and_release + 10
15 libdispatch.dylib              0x36ed9dab _dispatch_root_queue_drain + 866
16 libdispatch.dylib              0x36edacd7 _dispatch_worker_thread3 + 94
17 libsystem_pthread.dylib        0x37031e31 _pthread_wqthread + 668
18 libsystem_pthread.dylib        0x37031b84 start_wqthread + 8

Thread : Crashed: com.apple.root.default-qos
0  libsystem_kernel.dylib         0x36fb6dfc __pthread_kill + 8
1  libsystem_pthread.dylib        0x37034d37 pthread_kill + 62
2  libsystem_c.dylib              0x36f56909 abort + 76
3  libc++abi.dylib                0x362919c9 __cxa_bad_cast
4  libc++abi.dylib                0x362ab671 default_unexpected_handler()
5  libobjc.A.dylib                0x36970f25 _objc_terminate() + 192
6  libc++abi.dylib                0x362a8de3 std::__terminate(void (*)()) + 78
7  libc++abi.dylib                0x362a85a9 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)
8  libobjc.A.dylib                0x36970d5f objc_exception_throw + 250
9  CoreFoundation                 0x29096291 -[__NSSetM addObject:] + 608
10 EventKit                       0x29b4eacf -[EKPersistentObject primitiveRelationValueForKey:] + 502
11 Foundation                     0x29dc1617 -[NSObject(NSKeyValueCoding) valueForKey:] + 202
12 EventKit                       0x29b5afc5 -[EKObjectToManyRelation _loadedItems] + 120
13 EventKit                       0x29b5aef3 -[EKObjectToManyRelation _effectiveItems] + 102
14 EventKit                       0x29b5ae69 -[EKObjectToManyRelation items] + 20
15 EventKit                       0x29b5d179 -[EKCalendarItem attendees] + 36
16 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 ()) to @callee_unowned @objc_block (@unowned Swift.ImplicitlyUnwrappedOptional<ObjectiveC.EKEvent>, @unowned Swift.UnsafeMutablePointer<ObjectiveC.ObjCBool>) -> (@unowned ()) (WmBuildGroupsTask.swift)
19 EventKit                       0x29ba72a7 __60-[EKEventStore enumerateEventsMatchingPredicate:usingBlock:]_block_invoke + 130
20 EventKit                       0x29bad6af __41-[EKPredicateSearch startWithCompletion:]_block_invoke_2 + 690
21 libdispatch.dylib              0x36ed07bb _dispatch_call_block_and_release + 10
22 libdispatch.dylib              0x36ed9dab _dispatch_root_queue_drain + 866
23 libdispatch.dylib              0x36edacd7 _dispatch_worker_thread3 + 94
24 libsystem_pthread.dylib        0x37031e31 _pthread_wqthread + 668

line 9 ae WmBuildGroupsTask.swift:421 points to this row if event.attendees != nil{ . 9行ae WmBuildGroupsTask.swift:421 if event.attendees != nil{ WmBuildGroupsTask.swift:421指向此行。

Can anybody spread the light on how to get rid of this crash or at least make code safety from crash? 任何人都可以宣传如何摆脱这次崩溃或至少使代码安全免于崩溃?

[EDIT 1] [编辑1]

I tried also: 我也尝试过:

if event.hasAttendees {

  if let attArray:NSArray = event.attendees{ // crashes here

    /* ... */
  }                          

} }

Interesting that from command line: po event.hasAttendees returns true 有趣的是从命令行: po event.hasAttendees返回true

when po event.attendees return null . po event.attendees返回null But still crashes 但仍然崩溃

[EDIT 2] [编辑2]

After upgrade to Swift 1.2 get the same crashes (In Crashlytics). 升级到Swift 1.2后获得相同的崩溃(在Crashlytics中)。 Also tried: 还尝试过:

if event.hasAttendees {

  if let attArray:[EKParticipant] = event.attendees as? [EKParticipant] // crash here
 {
    /* ... */
  }                      
}

The problematic event(s) refers to calendar like Google and as I pointed above 99.5% the same event works properly and I success to fetch attendees. 有问题的事件是指谷歌这样的日历,正如我上面指出的那样,99.5%的同一事件正常工作,我成功获取与会者。

I'm not iOS Guru but looks like its internal iOS issue: 我不是iOS Guru,但看起来像是内部的iOS问题:

  libobjc.A.dylib                0x36970d5f objc_exception_throw + 250
9  CoreFoundation                 0x29096291 -[__NSSetM addObject:] + 608
10 EventKit                       0x29b4eacf -[EKPersistentObject primitiveRelationValueForKey:] + 502
11 Foundation                     0x29dc1617 -[NSObject(NSKeyValueCoding) valueForKey:] + 202
12 EventKit                       0x29b5afc5 -[EKObjectToManyRelation _loadedItems] + 120
13 EventKit                       0x29b5aef3 -[EKObjectToManyRelation _effectiveItems] + 102
14 EventKit                       0x29b5ae69 -[EKObjectToManyRelation items] + 20
15 EventKit                       0x29b5d179 -[EKCalendarItem attendees] + 36

Thanks, 谢谢,

It seems pretty clear that this is a bug in iOS and so you would need a hack to go around it until they fix it. 很明显,这是iOS中的一个错误,所以你需要一个黑客来解决它,直到他们修复它。

If it was Objective CI would've used a try catch block to try to catch the exception, so the app would not crash. 如果它是Objective CI将使用try catch块来尝试捕获异常,因此应用程序不会崩溃。

Here 's an example of using a try block in Swift, by using an Objective C implementation: 以下是使用Objective C实现在Swift中使用try块的示例:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过iOS中的calendarItemExternalIdentifier从EKEventStore获取EKEvent? - How to get EKEvent from EKEventStore by calendarItemExternalIdentifier in iOS? 从iOS日历应用程序中删除EKEventStore中的EKEvent - Delete EKEvent from EKEventStore from iOS Calendar App EKEventStore导致SpringBoard崩溃 - EKEventStore causes SpringBoard crash Apple Developer Swift教程问题-按下按钮导致iOS应用由于未捕获的异常&#39;NSInvalidArgumentException&#39;而崩溃 - Apple Developer Swift Tutorial issues - Pressing a button causes iOS app to crash due to uncaught exception 'NSInvalidArgumentException' Swift:从EKEventStore提取到tableView数据后,对EKEvents进行日期排序 - Swift: Date sorting EKEvents after fetching from EKEventStore into tableView data EKEvent / EKEventStore和时区 - EKEvent/EKEventStore and timezones 应用程式当机:iOS 8中的NSInvalidArgumentException - App crash: NSInvalidArgumentException in iOS 8 从 EKEventStore 获取事件的问题 - Problems fetching events from EKEventStore 从EKEventStore获取事件并在Swift iOS8中的tableView中显示 - Fetch events from EKEventStore and show in tableView in Swift iOS8 快速从核心数据获取会导致崩溃,因为我收到其他类型的对象 - Fetching from Core Data with swift causes crash because I receive other type of object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM