Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up weekly repeating UILocalNotifications with iOS 8 deprecations?

Prior to iOS 8, scheduling weekly repeating notifications was easy, we just assigned NSWeekCalendarUnit to the notification.repeatInterval value. Now with iOS 8, pretty much all the NSCalendarUnit values have been deprecated and replaced, mostly so Apple could rename them from NSDayCalendarUnit to NSCalendarUnitDay for consistency. However, they changed NSWeekCalendarUnit into NSCalendarUnitWeekOfMonth and NSCalendarUnitWeekOfYear, with no clear explanation of what the difference is, and the UILocalNotification documentation still talks in terms of the deprecated values.

I want a UILocalNotification to repeat every 7 days. I assumed NSCalendarUnitWeekOfMonth was the correct value, but when I use it, I get no repetition. Testing is time consuming, because each test takes a week!

Does anyone know which of the new week calendar units should be used for a weekly repeating local notification, or should the deprecated values continue to be used despite the warnings?

like image 281
Siegfoult Avatar asked Apr 20 '15 17:04

Siegfoult


1 Answers

Assuming Gregorian Calendar, it seems NSCalendarUnitWeekOfYear is value either from 1 - 53 or 0 - 52 which represents number of week within the calendar year. NSCalendarUnitWeekOfMonth is 1 - 5 or 0 - 4 which represents week within the month (Undocumented stuff, these are personal opinions ). In my experience i found NSCalendarUnitWeekOfYear working.

like image 67
Avi Avatar answered Sep 30 '22 13:09

Avi