如何从UILocalNotification对象中获取NEXT的日期 [英] How to grab the NEXT fire date from a UILocalNotification object

查看:118
本文介绍了如何从UILocalNotification对象中获取NEXT的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UILocalNotification对象,我已经设置了重复间隔的日,周和月。我没有遇到任何访问对象的火灾日期的麻烦:

I have a UILocalNotification object that I have setup with repeat intervals day, week, and month. I am having no troubles at all accessing the fire date of the object:

[cell.detailTextLabel setText:[notification1.fireDate description]];

但是我遇到了下一个火灾日期的麻烦。如果我打印出上述notification1对象到控制台,我得到这个:

But I am having troubles getting the next fire date. If I print out the above notification1 object to the console, I get this:

<UIConcreteLocalNotification: 0x613e060>{fire date = 2010-11-29 03:53:52 GMT, time zone = America/Denver (MST) offset -25200, repeat interval = 16, next fire date = 2010-11-30 03:53:52 GMT}

此对象包含某些值或数据,我需要显示下一个火焰日期...但我找不到它!有没有人知道我可以以程序方式获得它?

This object contains somewhere the value or data I need to display the next fire date...but I can't find it! Does anybody know where I can get it programmatically?

谢谢

推荐答案

我不认为下一个火灾日期可以作为一个属性,而是从 fireDate repeatInterval 计算。计算时间可能会随着不同的时区和其他令人讨厌的事情而复杂化。在您的例子中,您选择了每日重复,并计算下一个火灾日期,您可以按照以下方式执行某些操作:

I don't think the next fire date is available as a property but rather calculated from fireDate and repeatInterval. Date calculating can be tricky with different time zones and other nasty things. In your example you have chosen a daily repeat and to calculate the next fire date you can do something along the lines of:

NSCalendar *calendar = localNotif.repeatCalendar;
if (!calendar) {
  calendar = [NSCalendar currentCalendar];
}

NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
components.day = 1;
NSDate *nextFireDate = [calendar dateByAddingComponents:components toDate:localnotif.fireDate options:0];

如果您使用其他重复间隔,则必须相应地更改代码。如果要使用 NSMonthCalendarUnit ,则必须使用 components.month = 1

If you use some other repeat interval you would have to change the code accordingly. If you were to use NSMonthCalendarUnit you would have to use components.month = 1 instead.

这篇关于如何从UILocalNotification对象中获取NEXT的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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