0

对于我的项目,我使用 EventKit 访问 iPhone (iOS 5.1.1) 上的日历并从默认日历中获取所有事件。这很好用。对于我检查 hasAlarms 的每个事件,如果为真,我想知道警报的时间。所以,像这样:

for (EKEvent *ev in allEventsArray){
            if ([ev hasAlarms]){
                NSArray *alarms = ev.alarms;
                for (EKAlarm *alarm in alarms){
                    NSLog(@"%@",alarm.absoluteDate);
                }
            }
}

问题是我得到了 NSLog 的“(null)”。我不知道我做错了什么......

有人可以帮忙吗?提前谢谢了!

4

1 回答 1

2

EKAlarm will have an absoluteDate OR a relativeOffset. If absoluteDate is null then relativeOffset will have a value.

EKAlarm *alarmA = [EKAlarm alarmWithAbsoluteDate:[NSDate date]];
EKAlarm *alarmB = [EKAlarm alarmWithRelativeOffset: -300.0f];

NSLog(@"Absolute alarmA = %@", alarmA.absoluteDate);
NSLog(@"Absolute alarmB = %@", alarmB.absoluteDate);
NSLog(@"Relative alarmA = %f", alarmA.relativeOffset);
NSLog(@"Relative alarmB = %f", alarmB.relativeOffset);

NSLog resuts:

Absolute alarmA = 2012-07-27 00:19:06 +0000
Absolute alarmB = (null)
Relative alarmA = 0.000000
Relative alarmB = -300.000000
于 2012-07-27T00:25:25.457 回答