3

I get events from a web service in my application, every event has an unique identifier.

If the user wants to push that event to native calender I will save that event in native but how would I know if that event is already existing in the native Calendar as I can't set eventIdentifier property of EKEvent object

I tried subclassing EKEvent and adding my own identifier

eventStore = [[EKEventStore alloc] init];
MyEvent *event = [MyEvent eventWithEventStore:eventStore];
event.myEventIdentifier = @"MyEventIdentifier";
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
event.startDate = [NSDate date];
event.endDate = [NSDate dateWithTimeIntervalSinceNow:10000];
event.title = @"MyEventTitle";
[eventStore saveEvent:event span:EKSpanThisEvent error:nil];

But when I retrive event object I dont get my subclass object and it was throwing an exception when I called

[event valueForKey:@"MyEventIdentifier"];

Now as you can see, I can't set eventIdentifier property in EKEvent class, also subclassing EKEvent doesn't work.

How can I achieve the required functionality, any suggestions?

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
Yogesh Maheshwari
  • 1,324
  • 2
  • 16
  • 37

1 Answers1

3

Im looking into EKEvent for something similar, but EKEvent does has an identifier of which you can access.

Once you save the event, you can access its identifier,

NSString *eventID = [NSString stringWithFormat:@"%@", event.eventIdentifier];

Save this string and use it to remove the events, but note event.eventIdentifier is READ only,

Andyy
  • 485
  • 8
  • 27
  • 1
    I already knew that when i posted this question.. you would know all the events saved in native calender by keeping all eventIdentifiers but that data would be lost if user deleats the app from the device and if he again install the app you will have no idea about which of your events are existing in native calendar – Yogesh Maheshwari Jul 31 '12 at 20:01
  • Thank you so much. You gave me a clue. Thanks once again – Abdul Yasin Nov 13 '17 at 11:57