3

When I log the description of the local notification

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

And I found "repeat count" parameter. Is there any option to set the repeat count such that it will repeat for this no of count and expired

Gobi M
  • 3,243
  • 5
  • 32
  • 47

3 Answers3

0

A possible workaround was asked in this question. Cancelling single occurence of repeating local notification

But, as this suggests I dont think it is possible to have a repeating Local notification distinguished by its repeat count.

Community
  • 1
  • 1
Xcoder
  • 1,762
  • 13
  • 17
0

You couldnt set any repeat count for this purpose. But instead you can modify the fireDate with necessary checking after receiving notification and then it can be scheduled again.

- (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 ;
}

A small problem here is it only works when the didReceiveLocalNotification invoked.

manujmv
  • 6,450
  • 1
  • 22
  • 35
0

You can give the repeat count as a number. When notification fired in Appdelegate didReceiveLocalNotification method will be called. In that method you can get the repeat count. There you can decrease the repeat count and reschedule your notification. if the repeat count is 0 then you no need to reschedule that notification.

For example:

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

Hope this helps :)

kalyani puvvada
  • 496
  • 4
  • 12