4

While working with the EventKit on iPhone I noticed that some events can exist which cannot be modified. Examples I encountered so far are birthdays and events synced with CalDAV. When you view the event's details in the standard built-in calendar app on iPhone the "Edit" button in the top-right corner is not visible in these cases, where it would be visible when viewing "normal" events.

I've searched everywhere, read all documentation there is but I simply can't find anything that tells me how to detect this behavior! I can only detect it afterwards:

  1. edit an event's title
  2. save it to the event store
  3. check the event's title, if it has not changed it is not editable!

I am looking for a way that I can detect the non-editable behavior of an event beforehand. I know this is possible because I've seen other calendar apps implement this correctly.

Tom van Zummeren
  • 9,130
  • 12
  • 52
  • 63

5 Answers5

9

Ok it appears as if the SDK doesn't provide me with anything I can use to check if an EKEvent is read-only. I created a workaround by creating a category that adds an "isReadOnly" method to all EKEvent instances.

EKEvent+ReadOnlyCheck.h

@interface EKEvent(ReadOnlyCheck)
- (BOOL) isReadOnly;
@end`

EKEvent+ReadOnlyCheck.m

#import "EKEvent+ReadOnlyCheck.h"

@implementation EKEvent(ReadOnlyCheck)

- (BOOL) isReadOnly {
    BOOL readOnly;
    NSString *originalTitle = [self.title retain];
    NSString *someRandomTitle = [NSString stringWithFormat:@"%i", arc4random()];

    self.title = someRandomTitle;
    readOnly = [originalTitle isEqualToString:self.title];
    self.title = originalTitle;
    [originalTitle release];

    return readOnly;
}
@end

When the above files are in place I can simply call isReadOnly on the EKEvent of my choice.

#import "EKEvent+ReadOnlyCheck.h"
...
if ([event isReadOnly]) {
    // Do your thing
}
...
Tom van Zummeren
  • 9,130
  • 12
  • 52
  • 63
  • I have also gone through the documentation, this seems to be the only solution. :-( – Daniel T. Jan 03 '11 at 20:13
  • 2
    Years later, and we still have the issue. Setting the title doesn't seem to work (meaning it shows as changed) on iOS 6 for instance (using an Exchange calendar), but changing the date works (date remains the same). – alex-i Jan 14 '15 at 11:19
8

I haven't worked with Event Kit yet, but from the documentation it seems that editability is a property of a calendar, not of an event. event.calendar gets you the event's calendar, and calendar.allowsContentModifications tells you if the calendar is read-only or read-write.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • 2
    Thanks for your answer. I have looked into that property of a calendar already but it only works for birthdays. Also I'm sure this can't be determined on calendar level since it is possible that one event of a calendar is editable and another one isn't. If an event was synced onto the phone it is read-only but if I add a new event locally to the same calendar, it is editable. – Tom van Zummeren Dec 17 '10 at 23:13
1

Yes. It is possible. The code would look like following : Try relating to code by logging the output of objects I use with editable/non editable events and you will understand the working:)

EKEventViewController *controller = [[EKEventViewController alloc] init];
controller.event = myEvent; /*myEvent is of type EKEvent*/          
if(controller.navigationItem.leftBarButtonItem != NULL)
{
    /*Event is Editable, Your code here*/
}
Atulkumar V. Jain
  • 5,102
  • 9
  • 44
  • 61
Vivek Shah
  • 11
  • 1
1

I think adding this category method for EKEvent handles all cases where events are not editable:

- (BOOL)isReadOnly {
    if (self.calendar.allowsContentModifications == NO) return YES;
    if (self.organizer && [self.organizer isCurrentUser] == NO) return YES;
    return NO;
}
Matt Toohey
  • 106
  • 5
1

try allowsEditing property of EKEventViewController before displaying the view.

Harish
  • 11
  • 1