首页 文章

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

提问于
浏览
1

我正在使用 UILocalNotifications 实现提醒应用程序,并希望允许用户设置重复模式 . 对于重复模式使用 NSDayCalenderUnitNSWeekCalendarUnit 等 .

我没有在 LocalNotification 类中看到任何属性从通知中获取下一个开火日期 .

Example

“{fire date = 2013年9月6日星期五,印度标准时间上午7:05:00,时区=亚洲/加尔各答(GMT 05:30)偏移19800,重复间隔= NSWeekCalendarUnit,重复计数= UILocalNotificationInfiniteRepeatCount,下一次火灾date = 2013年9月6日星期五,上午7:05:00印度标准时间,用户信息= {\ n kRemindMeNotificationDataKey = \“测试通知\”; \ n}}“

请帮助我从本地通知中获取下一个开火日期 .

提前致谢 .

2 回答

  • 0

    您可以使用 UILocalNotification 中的两个属性:

    • fireDate

    • repeatInterval

    基于这两个属性创建NSDate .

    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *comps = [calendar components:self.localNotification.repeatInterval fromDate:self.localNotification.fireDate];
    
    NSDate *nextFireDate = [calendar dateFromComponents:comps];
    
  • 0

    试试这段代码

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

相关问题