0

I am trying to simulate the stock alarm app usage with the UserNotifications API but I am having hard time doing it.

For a single specific weekday (monday in this case) its all good.

NSDateComponents *components = [NSDateComponents new];

components.hour = 13;
components.minute = 0;
components.second = 0;
components.weekday = 2;

According to Apple: "The weekday units are the numbers 1 through N (where for the Gregorian calendar N=7 and 1 is Sunday)."

But if I want both monday and tuesday (should be 1 + 2?, which points to wednesday) I can't get it working.

This walkthrough also have detailed information. "To create a trigger that repeats at a certain interval use the correct set of date components. For example, to have the notification repeat daily at the same time we need just the hour, minutes and seconds:"

Bartu
  • 2,189
  • 2
  • 26
  • 50
  • A instance of `NSDate` refers to one point on time line. – Amin Negm-Awad Mar 08 '17 at 10:08
  • @AminNegm-Awad yes but this is an NSDateComponents, which does not refer one point on timeline. If I use the above mentioned piece of code, an alarm will be produced on each monday at 13:00. And with given api there should be a way to set alarm to both monday and tuesday with the given logic. – Bartu Mar 08 '17 at 10:09
  • It does, because an instance of `NSDataComponents` holds the components of an instance of `NSDate`, which points to one point on timeline. – Amin Negm-Awad Mar 08 '17 at 10:14
  • @AminNegm-Awad According to Apple Docs: "You represent the component elements of a date—such as the year, day, and hour—using an NSDateComponents object. An NSDateComponents object can hold either absolute values or quantities of units (see Adding Components to a Date for an example of using NSDateComponents to specify quantities of units). For date components objects to be meaningful, you need to know the associated calendar and purpose." So it may hold the components of an instance of NSDate but not necessarily. Which is the whole point of NSDateComponents. – Bartu Mar 08 '17 at 10:19
  • I think for your use case, you need 2 triggers, each for the day of the week you want. – Aris Mar 08 '17 at 10:32
  • @Bartu It holds the components of one single date. I cannot see any part of the documentation that says something else. The meaning of date components is to extract multiple *parts* of *one single* date, not to deal with more than one date. This is exactly, what the docs say. – Amin Negm-Awad Mar 08 '17 at 12:14

0 Answers0