简体   繁体   中英

EKAlarm / EKEvent

I am trying to create an app which has the ability to view calendar events. I am able to read all the properties but am having trouble with the EKAlarm. When I do an NSLog in the for loop it confirms that it should be hitting the 15min alarm log but it is passing over it.

for (int i = 0; i < [event1.alarms count]; i++) {

    if ([event1.alarms objectAtIndex:i]  ==  [EKAlarm alarmWithRelativeOffset:-900]) {
        NSLog(@"alarm: 15 min before");
    }else if([event1.alarms objectAtIndex:i] == [EKAlarm alarmWithRelativeOffset:-1800]) {
        NSLog(@"alarm: 30 min before");

    }else if([event1.alarms objectAtIndex:i] == [EKAlarm alarmWithRelativeOffset:-3600]) {
        NSLog(@"alarm: 1 hour before");

    }else if([event1.alarms objectAtIndex:i] == [EKAlarm alarmWithRelativeOffset:-86400]) {
        NSLog(@"alarm: 1 day before");

    }

}

What you're doing here is comparing pointers between the EKAlarms that you saved in your NSArray and newly created alarms that you're allocating at the time of the comparison.

What you could use to test for equality is the relativeOffset property in your alarms.

Something like:

for (int i = 0; i < [event1.alarms count]; i++) {

    NSTimeInterval offset = [[event1.alarms objectAtIndex:i] relativeOffset];

    if (offset == -900) {
        NSLog(@"alarm: 15 min before");
    }
    else if(offset == -1800) {
        NSLog(@"alarm: 30 min before");
    }
    else if(offset == -3600) {
        NSLog(@"alarm: 1 hour before");
    }
    else if(offset == -86400) {
        NSLog(@"alarm: 1 day before");
    }
}

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