简体   繁体   中英

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. For repeating mode used NSDayCalenderUnit , NSWeekCalendarUnit , etc..

I didn't see any property in LocalNotification class to get the next fire date from a notification.

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
kRemindMeNotificationDataKey = \\"Test Notification\\";\\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:

  1. fireDate
  2. repeatInterval

Create a NSDate based on these two properties.

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM