如何使用iOS 8弃用设置每周重复的UILocalNotifications? [英] How to set up weekly repeating UILocalNotifications with iOS 8 deprecations?

查看:48
本文介绍了如何使用iOS 8弃用设置每周重复的UILocalNotifications?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 8之前,安排每周的重复通知很容易,我们只为 notification.repeatInterval 值分配了 NSWeekCalendarUnit .现在,在iOS 8中,几乎所有的 NSCalendarUnit 值都已被弃用和替换,主要是为了让Apple可以将它们从 NSDayCalendarUnit 重命名为 NSCalendarUnitDay 以保持一致性.但是,他们将 NSWeekCalendarUnit 更改为 NSCalendarUnitWeekOfMonth NSCalendarUnitWeekOfYear ,但没有清楚说明两者之间的区别以及 UILocalNotification 文档仍在讨论已弃用的值.

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.

我希望 UILocalNotification 每7天重复 .我以为 NSCalendarUnitWeekOfMonth 是正确的值,但是当我使用它时,不会重复.测试非常耗时,因为每个测试都需要一个星期!

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?

推荐答案

假设格里高利历,看来 NSCalendarUnitWeekOfYear 的值是 1-53 0-52 ,代表日历年内的星期数. NSCalendarUnitWeekOfMonth 1-5 0-4 ,代表一个月中的一周(未记录的内容,这些是个人观点).根据我的经验,我发现NSCalendarUnitWeekOfYear可以正常工作.

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.

这篇关于如何使用iOS 8弃用设置每周重复的UILocalNotifications?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆