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

让人想犯罪 __ 提交于 2019-12-06 02:16:27

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/29754384/how-to-set-up-weekly-repeating-uilocalnotifications-with-ios-8-deprecations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!