开发者

Updating EKEvent

开发者 https://www.devze.com 2023-01-06 13:16 出处:网络
I\'m trying to make some changes to an EKEvent object in my calendar. I have an event for example from 1 a.m to 2 a.m. When I set the allDay property to YES, this event is changed correctly and appear

I'm trying to make some changes to an EKEvent object in my calendar. I have an event for example from 1 a.m to 2 a.m. When I set the allDay property to YES, this event is changed correctly and appears in the all day开发者_开发百科 section of the calendar. But it's not working the other way round. I'm setting the start and end time correctly and the allDay property to NO, but the event remains as it is. The time changes aren't updated. Here's what I'm doing:

EKEvent *event = [self.eventStore eventWithIdentifier:MY_IDENTIFIER];

NSDate *start = [NSDate date]; // Get the current time
NSDate *end = [start addTimeInterval:3600]; // Add one hour

event.startDate = start;
event.endDate = end;
event.allDay = NO;

// Set some other event properties like title, location....

NSError *error;
[self.eventStore saveEvent:event span:EKSpanThisEvent error:&error]; // Save changes and make them appear in the calendar

The changes work all and I don't get any errors - only the change allDay YES to NO doesn't work. I took a look on Apple's documentation and only found the information that the event's start and end dates can be set. I'm not sure if this means that allDay events are included and can be set, too.

Has anyone a solution for this?


Have you tried setting first allDayEvent = NO before setting up the start and end dates ? Also check the time zone property. All day events do not have one, but normal events can.


I have run into this with a shared calendar event on Google Apps Calendar. I have not come up with a solution as of yet, but if you create and or edit events that belong to you (at least with iCloud) then setting EKEvent.allDay = YES will have the desired effect.


Yes, I found some strange appearence when save the updated event. I have a trick method. You can delete the pre event,and save the new event. It work for me. Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号