2013-09-26 52 views
3

當我登錄本地通知如何添加重複計數或到期日爲本地通知

`<UIConcreteLocalNotification: 0x1edd4d40>{fire date = Thursday, September 26, 2013, 11:15:00 AM India Standard Time, time zone = Asia/Kolkata (GMT+05:30) offset 19800, repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Thursday, September 26, 2013, 11:15:00 AM India Standard Time, user info = { 
    UID = "38BF41F8-05D3-48E2-A20F-7B84609F4E85"; 
}}` 

的描述和我找到了「重複次數」參數。是否有任何選項可以設置重複次數,以便重複此次數計數並過期

+0

請解釋一下你想我CNT讓你:( – iPatel

+0

詢問是否有可能取消一週後本地通知時,重複間隔是什麼NSDaysCalendarUnit那樣? –

回答

0

您無法爲此設置任何重複計數。但是,您可以在收到通知後通過必要的檢查修改fireDate,然後再次安排。

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { 

    localNotif = notification; 

    int no_of_days = [self getNumberOfDaysToNextAlarmInDays]; 
    int day = 24*60*60; 
    NSTimeInterval interval = day *no_of_days; 
    localNotif.fireDate = [NSDate dateWithTimeInterval:interval sinceDate:[NSDate date]]; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 

} 



-(int)getNumberOfDaysToNextAlarmInDays { 

    //do the necessary calculations here 

    return count ; 
} 

這裏的一個小問題是,當didReceiveLocalNotification調用它纔會起作用。

0

您可以將重複計數作爲數字。當通知在AppdelegatedidReceiveLocalNotification方法將被調用。在該方法中,您可以獲得重複計數。在那裏你可以減少重複計數並重新安排你的通知。如果重複計數爲0,則無需重新計劃notification

例如:

if ([[notification.userInfo objectForKey:@"repeat"]intValue] != 0) { 
    //You can again schedule your notification here with decrementing the repeat count. 
}else{ 

} 
//Here you can cancel the current notification 
[[UIApplication sharedApplication]cancelLocalNotification:notification]; 

希望這有助於:)