EventKit - App freezes when adding an EKEvent with 2 alarms (iOS 5)

早过忘川 提交于 2019-12-01 03:34:17

问题


I have an app that programmatically adds reminders to your iOS device's calendar.

Previous to iOS 5, I could add a calendar item with two alarms thusly:

EKEventStore* eventStore = [[EKEventStore alloc] init];
EKEvent* event = [EKEvent eventWithEventStore:eventStore];
// set startDate, endDate, title, location, etc.

[event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -5.0f]]; // 5 min
[event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -15.0f]]; // 15 min

[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError* error = nil;
BOOL success = [eventStore saveEvent:event span:EKSpanThisEvent error:&error]; 

On iOS 5 this freezes the application. It does not return with an error - it just never returns.

If I only call addAlarm once, it works as expected.

On iOS 4.2, calling addAlarm twice works just fine.

Am I doing something wrong?


回答1:


Its a bug with Apple. If you set 2 alarms it causes the app to freeze. If you only set 1 it works just fine. This is fixed in iOS 5.1 .




回答2:


If you take a look at the EventKit section in the iOS 5 changes from iOS 4.3 document, it mentions that some items are deprecated for EKEvent. The hierarchy has changed and a new abstract superclass has been added: EKCalendarItem.




回答3:


have you tried calling addAlarm using a variable?

EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:60.0f * -5.0f]]; // 5 min
[event addAlarm:alarm];

EKAlarm *alarm2 = [EKAlarm alarmWithRelativeOffset:60.0f * -15.0f]]; // 15 min
[event addAlarm:alarm2];



回答4:


I had the same error.

The problem seems that startDate shoudln't be the same as endDate... really silly iOS change!



来源:https://stackoverflow.com/questions/7844402/eventkit-app-freezes-when-adding-an-ekevent-with-2-alarms-ios-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!