IPhone: how to determine if an EKEvent instance can be changed?

While working with EventKit on the iPhone, I noticed that there may be some events that cannot be changed. Examples I came across include birthdays and events synchronized with CalDAV. When you view the event information in the standard built-in calendar application on the iPhone, the "Edit" button in the upper right corner is not visible in these cases, where it will be visible when viewing "ordinary" events.

I searched everywhere, read all the documentation, but I just can't find anything that tells me how to detect this behavior! I can only detect it later:

  • change event name
  • save it to the event store
  • check the event header, if it has not changed, it is not editable!

I am looking for a way in which I can pre-detect the unwritten behavior of an event. I know this is possible because I have seen other calendar applications implement this correctly.

+3
source share
5 answers

Well, it looks like the SDK does not provide me with anything that I can use to check if EKEvent is read-only. I created a workaround by creating a category that adds the 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 isReadOnlyin EKEvent of my choice.

#import "EKEvent+ReadOnlyCheck.h"
...
if ([event isReadOnly]) {
    // Do your thing
}
...
+8
source

Event Kit, , , . event.calendar , calendar.allowsContentModifications , -.

+7

EKEventViewController .

+1

. . : , , , / , , :)

EKEventViewController *controller = [[EKEventViewController alloc] init];
controller.event = myEvent; /*myEvent is of type EKEvent*/          
if(controller.navigationItem.leftBarButtonItem != NULL)
{
    /*Event is Editable, Your code here*/
}
+1

, EKEvent , :

- (BOOL)isReadOnly {
    if (self.calendar.allowsContentModifications == NO) return YES;
    if (self.organizer && [self.organizer isCurrentUser] == NO) return YES;
    return NO;
}
0

Source: https://habr.com/ru/post/1780952/


All Articles