简体   繁体   English

EKAlarm不会在iOS 5中设置

[英]EKAlarm will not set in iOS 5

I wrote the following snippet to create an event. 我编写了以下代码片段来创建一个事件。 Setting the alarm works fine in iOS 4, but in iOS 5 it doesn't get set. 设置闹钟在iOS 4中运行良好,但在iOS 5中它没有设置。 Is this a bug or am I missing something? 这是一个错误还是我错过了什么?

EKCalendar *cal = [self.eventStore defaultCalendarForNewEvents];
EKEvent *event = [EKEvent eventWithEventStore:self.eventStore];
event.calendar = cal;
// .......
EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:-3600];
event.alarms = [NSArray arrayWithObject:alarm];
// .......

I had the same error. 我有同样的错误。

The problem seems that startDate shoudln't be the same as endDate ... really silly iOS change! 问题似乎startDateendDate不一样 ......真是愚蠢的iOS变化!

It seems to be related to that's happening in this ticket: EventKit - App freezes when adding an EKEvent with 2 alarms (iOS 5) . 它似乎与此票证中发生的情况有关: EventKit - 在添加带有2个警报的EKEvent(iOS 5)时应用程序冻结

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. 如果您查看iOS 4.3文档中iOS 5更改中的EventKit部分,则会提到某些项目已弃用EKEvent。 The hierarchy has changed and a new abstract superclass has been added: EKCalendarItem . 层次结构已更改,并添加了新的抽象超类: EKCalendarItem

Avoid manipulating the alarms array. 避免操纵警报阵列。 You need to add the alarm to your event like this: 您需要将警报添加到您的事件中,如下所示:

EKAlarm *reminder = [EKAlarm alarmWithRelativeOffset:-300];
[event addAlarm:reminder];

This will add a reminder 5 minutes before the start time. 这将在开始时间前5分钟添加提醒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM