How to set up weekly recurrence of UILocalNotifications with iOS 8 exemptions?

Prior to iOS 8, scheduling weekly recurring notifications was simple, we just set NSWeekCalendarUnit to notification.repeatInterval . Now with iOS 8, almost all NSCalendarUnit values NSCalendarUnit deprecated and replaced, basically, so Apple can rename them from NSDayCalendarUnit to NSCalendarUnitDay to ensure consistency. However, they changed NSWeekCalendarUnit to NSCalendarUnitWeekOfMonth and NSCalendarUnitWeekOfYear without a clear explanation of the differences, and the UILocalNotification documentation still speaks of outdated values.

I want UILocalNotification to be repeated every 7 days . I assumed that the NSCalendarUnitWeekOfMonth value was correct, but when I use it, I do not get a repetition. Testing takes a lot of time because each test takes a week!

Does anyone know which of the calendar units of the new week should be used for weekly re-local notification, or if outdated values ​​continue to be used despite warnings?

+6
source share
1 answer

Assuming a Gregorian calendar , it seems that NSCalendarUnitWeekOfYear is a value from either 1 - 53 or 0 - 52 , which represents the number of weeks in a calendar year. NSCalendarUnitWeekOfMonth 1 - 5 or 0 - 4 , which represents a week for a month (undocumented materials, these are personal opinions). In my experience, I have found that NSCalendarUnitWeekOfYear works.

+7
source

Source: https://habr.com/ru/post/985539/


All Articles