0

I build an application that fetches ekevents from calendar (by EKEventStore predicateForEventsWithStartDate:endDate:calendars:) and synchronize app-events with calendars (with EKEventStore saveEvent:span:commit:error:).

I use a static reference to the EKEventStore and make sure that the EKEventStore is not accessed simultaneously by my different processes.

The app is sometimes terminated by a Springboard crash on IOS7. Here is a backtrace of the crash.

Last Exception Backtrace:
0   CoreFoundation                  0x18625e950 __exceptionPreprocess + 132
1   libobjc.A.dylib                 0x1927641fc objc_exception_throw + 60
2   CoreFoundation                  0x18625e810 +[NSException raise:format:arguments:] +     116
3   Foundation                      0x186d96db4 -[NSAssertionHandler     handleFailureInMethod:object:file:lineNumber:description:] + 112
4   EventKit                        0x186adab84 -[EKEventStore _addFetchedObjectWithID:] + 240
5   EventKit                        0x186adaa64 __78-[EKEventStore registerFetchedObjectWithID:withDefaultLoadedProperties:inSet:]_block_invoke + 96
6   libdispatch.dylib               0x192d3bfd4 _dispatch_client_callout + 16
7   libdispatch.dylib               0x192d41c84 _dispatch_barrier_sync_f_invoke + 48
8   EventKit                        0x186ada990 -[EKEventStore     registerFetchedObjectWithID:withDefaultLoadedProperties:inSet:] + 148
9   EventKit                        0x186ae1458 __41-[EKPredicateSearch startWithCompletion:]_block_invoke + 796
10  EventKit                        0x186ae1050 -[EKDaemonConnection _processReplyWithID:data:finished:] + 220
11  EventKit                        0x186ae0f5c CADReceiveReply + 136
12  EventKit                        0x186ae0eac _XReply + 124
13  EventKit                        0x186ae0e04 ClientCallbacks_server + 100
14  libdispatch.dylib               0x192d3fae8 dispatch_mig_server + 352
15  EventKit                        0x186ae0d6c __43-[EKDaemonConnection initWithOptions:path:]_block_invoke16 + 44
16  libdispatch.dylib               0x192d3bfd4 _dispatch_client_callout + 16
17  libdispatch.dylib               0x192d3db90 _dispatch_source_invoke + 500
18  libdispatch.dylib               0x192d430f4 _dispatch_root_queue_drain + 104
19  libdispatch.dylib               0x192d434fc _dispatch_worker_thread2 + 76
20  libsystem_pthread.dylib         0x192ed16bc _pthread_wqthread + 356
21  libsystem_pthread.dylib         0x192ed154c start_wqthread + 4

Here is my code initalizing my ekeventstore:

+ (EKEventStore *) sharedStore {
     static EKEventStore *sharedEventStore;

    if (sharedEventStore == nil) {
        sharedEventStore = [[EKEventStore alloc] init];
        [sharedEventStore requestAccessToEntityType: EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        }];
        [sharedEventStore reset];
    }

    return sharedEventStore;
}

Code to fetch events:

NSPredicate *predicate = [[CalendarHelper sharedStore] predicateForEventsWithStartDate:startDate
                                                        endDate:endDate
                                                      calendars:[[showableCalendars copy] autorelease]];
NSArray *result = [[CalendarHelper sharedStore] eventsMatchingPredicate:predicate];

And to update / create events:

EKEvent *event = [[CalendarHelper sharedStore] eventWithIdentifier:eventId];
if(event != nil) {
    event.title = title;
    event.startDate = startDate;
    event.endDate = endDate;
    NSLog(@"Updating...");
    NSLog(@"+++ %@", event.eventIdentifier);

    [[CalendarHelper sharedStore] saveEvent:event span:EKSpanThisEvent commit:commit error:nil];
    NSLog(@"Updated.");
}
else {
    NSLog(@"No event, no update");
}

Any clue?

Nico
  • 1,580
  • 14
  • 21
  • What code did you use? Have you asked permissions first? `requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)` – chrisblomm Apr 14 '14 at 10:04
  • Thanks Chris, Yes I asked permissions first, I edited my query above to include code snippets. – Nico Apr 14 '14 at 10:10
  • When is the app terminated? Did you already used breakpoints to pinpoint the problem? – chrisblomm Apr 14 '14 at 10:45
  • App terminates most often a few moments (ie 1 second) after having saved a bunch of events ; sometimes, it crashes even after the app has been put in background ; Breakpoints don't seem to be a solution to investigate as the crash is very hard to reproduce (1 time out of a few dozens approximatively)... – Nico Apr 14 '14 at 10:58

1 Answers1

2

Kindly check your ios version.. I experienced a similar crash when working with iOS 7.0.2, if its not try the below code

it seems like the cause of this bug is related to how many events we are trying to get in our app. Check on the apple's bug report (15424747).

It appears that this bug is introduced when our app does predicate on the eventStore with a large range of dates.

Here is the code:

NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate     endDate:endDate calendars:nil]; 

//for sorting we used NSSortDescriptor

if (!self.masterListSortDescriptor)
{    
    self.masterListSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"startDate"  ascending:YES]; 
}

NSArray *result = [[self.eventStore eventsMatchingPredicate:predicate]
sortedArrayUsingDescriptors:@[self.masterListSortDescriptor]];
abhi
  • 620
  • 5
  • 14
  • my app has a predicate range of 2 weeks, do you think this could cause the crash (I have similar crash description) – Async- Dec 15 '16 at 09:47