简体   繁体   中英

EKAlarm absoluteDate is null

for my project I am using the EventKit to access the calendar on an iPhone (iOS 5.1.1) and get all Events from the default calendar. That works fine. For each event I check hasAlarms, if true, I want to know the time of the alarm. So, something like this:

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

The problem is that I get "(null)" for the NSLog. I have no idea what I am doing wrong...

Can anybody help? Many thanks in advance!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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