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:
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.
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
}
...