对于我的项目我使用EventKit访问iPhone(iOS 5.1.1)上的日历,并从默认日历中获取所有事件。这很好。对于每个事件,我检查hasAlarms,如果为true,我想知道警报的时间。所以,像这样:
for (EKEvent *ev in allEventsArray){
if ([ev hasAlarms]){
NSArray *alarms = ev.alarms;
for (EKAlarm *alarm in alarms){
NSLog(@"%@",alarm.absoluteDate);
}
}
}
问题是我得到NSLog的“(null)”。我不知道我做错了什么......
有人可以帮忙吗?非常感谢提前!
答案 0 :(得分:2)
EKAlarm将有absoluteDate
或relativeOffset
。如果absoluteDate为null,则relativeOffset将具有值。
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重新开始:
Absolute alarmA = 2012-07-27 00:19:06 +0000
Absolute alarmB = (null)
Relative alarmA = 0.000000
Relative alarmB = -300.000000