EventKit - 添加带有 2 个警报的 EKEvent 时应用程序冻结 (iOS 5)
我有一个应用程序,可以通过编程方式将提醒添加到 iOS 设备的日历中。
在 iOS 5 之前,我可以这样添加一个带有两个闹钟的日历项目:
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];
在 iOS 5 上,这会冻结应用程序。它不会返回错误 - 它只是永远不会返回。
如果我只调用一次 addAlarm,它就会按预期工作。
在 iOS 4.2 上,调用 addAlarm 两次就可以了。
我做错了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是苹果的一个错误。如果您设置 2 个闹钟,则会导致应用程序冻结。如果你只设置 1,它就可以正常工作。这在 iOS 5.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 .
如果您查看 iOS 5 中的 EventKit 部分相对于 iOS 4.3 的更改 文档,它提到 EKEvent 已弃用某些项目。层次结构已更改,并添加了新的抽象超类: EKCalendarItem。
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.
您是否尝试过使用变量调用 addAlarm ?
have you tried calling addAlarm using a variable?
我有同样的错误。
问题似乎是 startDate 不应该与 endDate 相同......真是愚蠢的 iOS 更改!
I had the same error.
The problem seems that startDate shoudln't be the same as endDate... really silly iOS change!