简体   繁体   English

如何从本地通知中获取下一个开火日期?

[英]How do I get next fire date from a local notification..?

I am implementing a reminder application using UILocalNotifications , and want to allow user to set repeat mode. 我正在使用UILocalNotifications实现提醒应用程序,并希望允许用户设置重复模式。 For repeating mode used NSDayCalenderUnit , NSWeekCalendarUnit , etc.. 对于重复模式,请使用NSDayCalenderUnitNSWeekCalendarUnit等。

I didn't see any property in LocalNotification class to get the next fire date from a notification. 我在LocalNotification类中没有看到任何属性可以从通知中获取下一个触发日期。

Example

"{fire date = Friday, September 6, 2013, 7:05:00 AM India Standard Time, time zone = Asia/Kolkata (GMT+05:30) offset 19800, repeat interval = NSWeekCalendarUnit, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Friday, September 6, 2013, 7:05:00 AM India Standard Time, user info = {\\n “ {发射日期= 2013年9月6日星期五,印度标准时间,时区=亚洲/加尔各答(GMT + 05:30)偏移19800,重复间隔= NSWeekCalendarUnit,重复计数= UILocalNotificationInfiniteRepeatCount,下一次火灾日期= 2013年9月6日,星期五,印度标准时间上午7:05:00,用户信息= {\\ n
kRemindMeNotificationDataKey = \\"Test Notification\\";\\n}}" kRemindMeNotificationDataKey = \\“测试通知\\”; \\ n}}“

Any one please help me out to get the next fire date from a local notification. 任何人都可以帮助我,从本地通知中获取下一个开火日期。

Thanks in advance. 提前致谢。

You have two properties from UILocalNotification which you can use: 您可以使用UILocalNotification两个属性:

  1. fireDate 消防日期
  2. repeatInterval repeatInterval

Create a NSDate based on these two properties. 基于这两个属性创建一个NSDate。

NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *comps = [calendar components:self.localNotification.repeatInterval fromDate:self.localNotification.fireDate];

NSDate *nextFireDate = [calendar dateFromComponents:comps];

try this code 试试这个代码

NSCalendar *calendar = notification.repeatCalendar;
components.week = 1;
         if (!calendar) {
             calendar = [NSCalendar currentCalendar];
         }            
NSDate *nextFireDate = [calendar dateByAddingComponents:components toDate:notification.fireDate options:0];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置本地通知从存储在数组中的日期开始触发? - How to set a local notification to fire from a date stored in an array? kCFCalendarUnitQuarter未设置通知的下一个触发日期以每季度触发一次通知 - kCFCalendarUnitQuarter not setting next fire date for the notification to fire notification quarterly 如何在特定日期之后停止计划的本地通知的触发? - How do I stop a scheduled local notification from triggering after a particular date? 如何从UIDatePicker获取正确的日期以进行本地通知 - How to get the right date from UIDatePicker for Local Notification nextTriggerDate() 不返回“预期”值,是否有另一种方法可以获取重复本地通知的下一个触发日期? - nextTriggerDate() doesn't return the 'expected' value, is there another way to obtain the next fire date of a repeating Local Notification? 从Swift 3中的日期选择器安排使用火灾日期的每周可重复本地通知 - Scheduling weekly repeatable local notification with fire date from date picker in Swift 3 如何从本地通知中打开特定的视图控制器? - How do I open a specific view controller from local notification? 苹果推送通知..拒绝? - Apple push notification.. refused? 如何迅速启动本地通知? - how to fire local notification on time in swift? 如何在背景模式下触发本地通知? - How to fire a local notification in backround mode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM