ios - 当与 UILocalNotification repeatInterval 一起使用时,NSMonthCalendarUnit 和 NSYearCalendarUnit 的行为如何?

标签 ios objective-c uilocalnotification repeat

NSMonthCalendarUnit 的行为如何与 UILocalNotification repeatInterval 完全相关?

查找下个月的同一天?

查找 30 天后的日期?

例如: 如果我创建一个日期为:27/02/2015 和 repeatInterval:NSMonthCalendarUnit 的 UILocalNotification,下一个通知是什么时候?不要介意 2 月是 27 日还是 28 日。只要考虑它始终是 28 日即可。这不是真正的问题。

重复是在 27/03/2015 还是 29/03/2015?

同样的问题也适用于 NSYearCalendarUnit。它只是增加了 365 天还是意味着明年的同一天,同一个月 (27/03/2016)?

最佳答案

我会把它作为编辑发布,但它有点长。

我想这确实是基于单位的。例如,如果您创建一个日期为 2015 年 2 月 2 日的 uilocalnotification 并为其指定一个 NSMonthCalendarUnit,它将在每个月的时间间隔内为同一日期再次调用它。

2015 年 2 月 2 日分解为 NSDayCalendarUnit=2,NSMonthCalendarUnit=2 NSYearCalendarUnit=2015。因此,对于任何 NSMonthCalendarUnit,只要 NSDayCalendarUnit=2 和 NSYearCalendarUnit=2015 就会调用通知。 (所以如果你在月底做了一个闰年日期,比如 1 月 30 日,而 2 月是一个闰年月份,它就不会被调用。)所以,这将有相同的日期和年份永远是 NSMonthCalendarUnit。除了年份之外,年份也是如此。

增加天数没有多大意义。想象一下,将某个日期的 NSMonth 间隔设置为第一个日期,并在同月的 31 日返回,这将不是一个非常实用的 API。

关于ios - 当与 UILocalNotification repeatInterval 一起使用时,NSMonthCalendarUnit 和 NSYearCalendarUnit 的行为如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27863060/

相关文章:

objective-c - Objective C : Version of JSON library I'm compiling in present in another library I'm linking in via . a,如何解决冲突?

ios - Storyboard - 如何在没有动画和显示屏幕的情况下自动执行转场

ios - UILocalNotification 根本不起作用

ios - 如何在swift 3中每天在特定时间触发本地通知

iphone - 在多个设备上测试一个 iPhone 应用程序

ios - UICollectionView Header 在 IBAction 中更改高度

ios - 需要帮助使用 NSXMLParser 和 ASIHTTPRequest

jquery - 从非原生 jquery webapp iOS 调用条码扫描器

iphone - 如何在 iOS 应用程序中检查下载的图像是否已损坏?

ios - 在幻灯片上停止 UILocalNotification Sound 以查看