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";
}}`

我找到了“重复计数”参数。是否有任何选项可以设置重复计数,以便它将重复此计数并过期

4

3 回答 3

0

您可以将重复计数作为数字给出。当在方法中触发通知时Appdelegate didReceiveLocalNotification将被调用。在该方法中,您可以获得重复计数。在那里,您可以减少重复次数并重新安排您的通知。如果重复计数为 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];

希望这可以帮助 :)

于 2013-09-26T06:30:58.797 回答
0

在这个问题中提出了一种可能的解决方法。取消单次重复本地通知

但是,正如这表明的那样,我认为不可能有一个重复的本地通知,以其重复计数来区分。

于 2013-09-26T06:20:07.813 回答
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时才有效。

于 2013-09-26T06:26:51.727 回答