Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS App Error: I screwed up somewhere in date calculation

My app crashing randomly, I can't generate same case that occurs in user's devices, here more details from the crash report:

Crash CLASS:

NSInternalInconsistencyException

FUNCTION:

-[CalendarViewController deleteEvent:] 

The method implementation is like this:

  -(void) deleteEvent: (EKSpan ) span :(EKEvent *) eventToDelete{

    NSError* error = nil;

    [sharedEventStore removeEvent:eventToDelete span:span error:&error];

   // refresh the UI   
}

Stacktrace:

0 CoreFoundation 0x33acf2a3 <redacted> + 162
1 libobjc.A.dylib 0x3b7ec97f objc_exception_throw + 30
2 CoreFoundation 0x33acf15d <redacted> + 0
3 Foundation 0x343a4ab7 <redacted> + 90
4 EventKit 0x34208b33 <redacted> + 1642
5 EventKit 0x342084c1 <redacted> + 408
6 EventKit 0x342091f7 <redacted> + 306
7 EventKit 0x341fa199 <redacted> + 144
8 EventKit 0x341fa0ff <redacted> + 30
9 Calendar 0x0010acaf -[CalendarViewController deleteEvent:] + 126
10 Calendar 0x0016f585 -[BlockAlertView dismissWithClickedButtonIndex:animated:] + 196
11 UIKit 0x359c20c5 <redacted> + 72
12 UIKit 0x359c2077 <redacted> + 30
13 UIKit 0x359c2055 <redacted> + 44
14 UIKit 0x359c190b <redacted> + 502
15 UIKit 0x359c1e01 <redacted> + 488
16 UIKit 0x358ea5f1 <redacted> + 524
17 UIKit 0x358d7801 <redacted> + 380
18 UIKit 0x358d711b <redacted> + 6154
19 GraphicsServices 0x375ed5a3 <redacted> + 590
20 GraphicsServices 0x375ed1d3 <redacted> + 34
21 CoreFoundation 0x33aa4173 <redacted> + 34
22 CoreFoundation 0x33aa4117 <redacted> + 138
23 CoreFoundation 0x33aa2f99 <redacted> + 1384
24 CoreFoundation 0x33a15ebd CFRunLoopRunSpecific + 356
25 CoreFoundation 0x33a15d49 CFRunLoopRunInMode + 104
26 GraphicsServices 0x375ec2eb GSEventRunModal + 74
27 UIKit 0x3592b301 UIApplicationMain + 1120
28 Calendar 0x000f9533 main + 66
29 Calendar 0x0008a6a8 start + 40 

Please note that I use one instance of EKEventStore in singleton pattern:

// this is in separate class

static EKEventStore *eventStore = nil;

    + (EKEventStore *)getEventStoreInstance
    {

        if (eventStore == nil){
            @synchronized(self){
                if (eventStore == nil){
                    eventStore = [[EKEventStore alloc] init];
                }
            }
        }

        return(eventStore);
    }

Any possible reason for this crash?

like image 549
Mohammad Rabi Avatar asked Mar 04 '13 09:03

Mohammad Rabi


Video Answer


1 Answers

It's definitely a bug. You can crash the iPad's calendar app with the following:

  1. Create an event, recurring every day with recurringEnd some days in future.
  2. Change the location of the second occurrence and save it for all future events.
  3. Delete first occurrence and do select only this event. BAM!

This does not happen, when the location change starts with an occurrence after the second OR when delete all future events was chosen. When you do the steps in code, your app crashes with the wounderful "I screwed up..."

A short work around is:

[eventStore removeEvent:firstEvent span:(firstEvent.isDetached ? EKSpanFutureEvents : desiredSpan) commit:YES error:nil];
like image 79
Thomas M Avatar answered Oct 08 '22 06:10

Thomas M