2013-09-05 11 views
1

我正在使用UILocalNotifications實現提醒應用程序,並且希望允許用戶設置重複模式。對於重複使用的模式NSDayCalenderUnitNSWeekCalendarUnit,等等。如何從本地通知中獲取下一個啓動日期..?

我沒有看到LocalNotification類中的任何屬性從通知中獲取下一個着火日期。

「{火日期=週五, 2013年9月6日,上午7點05分00秒印度標準時間,時區= 亞洲/加爾各答(GMT + 05:30)偏移19800,重複間隔= NSWeekCalendarUnit,重複計數爲 UILocalNotificationInfiniteRepeatCount,未來火日期=週五, 2013年9月6日,上午七時05分00秒印度標準時間,用戶信息= {\ n
kRemindMeNotificationDataKey = \「測試通知「; \ n}}」

任何人請幫助我從本地通知中獲取下一個啓動日期。

在此先感謝。

回答

0

你必須從UILocalNotification兩個屬性,你可以使用:

  1. fireDate
  2. 按repeatInterval

基於這兩個屬性創建一個NSDate的。

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

NSDate *nextFireDate = [calendar dateFromComponents:comps]; 
+0

謝謝,其實我是新來的本地通知。我添加了一個星期重複模式的任務,重複間隔爲256.那麼,如何使用該間隔和fireDate創建下一個啓動日期。 – Karthik

+0

fireDate:2013-09-06 13:34:00 +0000 repeatInterval:16(NSDayCalendarUnit) 而我得到了0001-01-05 18:06:32 +0000而不是2013-09-07 13:34: 00 +0000 – Karthik

+0

您不需要創建下一個啓動日期。在重複模式下,它會使用repeatInterval中的NSCalendarUnit自動創建下一個啓動日期。我寫的答案是讓你知道你是否明確地需要它。否則爲發射LocalNotifications你不需要給它另一個fireDate在重複模式的情況下 –

0

試試這個代碼

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