krusty
krusty

Reputation: 41

Is there any way to add identifier or tag custom event added in iCal?

I am setting a reminder in my app. I have added a custom event using EKEvent to iCal. Now when I retrieve events from iCal I get all the events present on that day. Is there any way to get/retrieve events added through my app only, I tried eventIdentifier property of EKEvent but it is a readonly property. Can anybody help???

Upvotes: 4

Views: 2199

Answers (2)

THE_DOM
THE_DOM

Reputation: 4296

You could loop through all of the calendar events that match a specific date but that is not the preferred method. Each event is created with a unique eventIdentifier property. When you save the event you can copy the eventIdentifier and next time you want to modify that specific event you can use the EKEventStore eventWithIdentifier Method to load your Event.

A sample might look like this

   EKEventStore *eventStore = [[EKEventStore alloc] init];
   NSError *err;
   EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
   //modify all the event properties you would like then save
   [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
   self.calendarEventID = event.eventIdentifier; 
   [eventStore release];

Later if you want to retrieve the saved event from the previous code you could do the following

   //self.calendarEventID is a NSString property declared in the .h file and synthesized in .m
   EKEvent *myEvent = [eventStore eventWithIdentifier:self.calendarEventID];

Upvotes: 2

Wienke
Wienke

Reputation: 3733

Kludge:

I had a similar problem with an AppleScript I made for setting iCal alarms; I wanted to be able to identify and delete the events my script had made on the next pass.

I couldn't find any tag-like properties for iCal events, so I ended up using the location property, which is a string; I set it to " " and searched for that. (Caveat: The alarm message includes the location at the end, surrounded by parens, so this glops things up a bit.)

If you need the location property for other purposes in your app, you still might be able to add some identifying character sequence. Or maybe you can use some other property you don't otherwise need.

Upvotes: 1

Related Questions