7

I want to create a reminder from my app, so I've created a reminder (EKReminder) and set up an alarm:

NSTimeInterval timeInterval = 100000;
NSDate *alarmDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:alarmDate];
[reminder setAlarms:@[alarm]];

but I see there is also a dueDateComponents property on EKReminder. What is the difference between setting an alarm and the dueDateComponents?

Also there there is a method to create an alarm: alarmWithRelativeOffset:(NSTimeInterval)offset but the docs say the offset argument can be negative, how is it possible to have an alarm in the past?

Jonathan.
  • 53,997
  • 54
  • 186
  • 290

3 Answers3

9

a EKReminder item is kind of like a task on a todo list with an optional start date and due date, the dueDateComponents property allows you to specify when a task should be completed. It'll allow you to show overdue items for example. This is informational and is separate from an alarm.

Setting an alarm on a reminder will cause the Reminders app to notify the user when the alarm goes off.

I guess this is slightly confusing because the Reminders app doesn't appear to let you set a due date, only an alarm date. However on this blog post it shows how you used to be able to set a due date but no reminder date on icloud.com: http://blog.truthdialogue.com/2012/07/setting-due-dates-in-the-os-x-mountain-lion-reminders-app.html. It looks as if Apple have simplified the apps since the API was developed.

The offset for alarmWithRelativeOffset: is from the start date/time of an event. So you can set an alarm to go off x minutes before an event for example.

Andrew Tetlaw
  • 2,669
  • 22
  • 27
1
let alarmist : EKAlarm = EKAlarm()
alarmist.relativeOffset = -0
reminder.addAlarm(alarmist)
NSLog("reminder has alarm ->" + reminder.hasAlarms.description)
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Larry Ricker
  • 199
  • 1
  • 7
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Donald Duck Sep 04 '17 at 12:24
0
 EKAlarm *reminder = [EKAlarm alarmWithRelativeOffset:-00];
        [event addAlarm:reminder];
varun
  • 317
  • 1
  • 4
  • 18