Question

I have a requirement in which I need to alert user say after every one day or after every two days and so on, even if application is not running.

I checked UILocalNotfication class where we have a property: repeatInterval. Here we can pass one of these values:

   NSEraCalendarUnit = kCFCalendarUnitEra,
   NSYearCalendarUnit = kCFCalendarUnitYear,
   NSMonthCalendarUnit = kCFCalendarUnitMonth,
   NSDayCalendarUnit = kCFCalendarUnitDay,
   NSHourCalendarUnit = kCFCalendarUnitHour,
   NSMinuteCalendarUnit = kCFCalendarUnitMinute,
   NSSecondCalendarUnit = kCFCalendarUnitSecond,
   NSWeekCalendarUnit = kCFCalendarUnitWeek,
   NSWeekdayCalendarUnit = kCFCalendarUnitWeekday,
   NSWeekdayOrdinalCalendarUnit = kCFCalendarUnitWeekdayOrdinal,
   NSQuarterCalendarUnit = kCFCalendarUnitQuarter,
   NSWeekOfMonthCalendarUnit = kCFCalendarUnitWeekOfMonth,
   NSWeekOfYearCalendarUnit = kCFCalendarUnitWeekOfYear,
   NSYearForWeekOfYearCalendarUnit = kCFCalendarUnitYearForWeekOfYear
   NSCalendarCalendarUnit = (1 << 20),
   NSTimeZoneCalendarUnit = (1 << 21)

So if I need to schedule a notification every day I can use NSDayCalendarUnit, but I found no way to schedule it alternatively.

If app is running I can fire a new notification in applicationDidRecieveLocalNotification with fireDate as [[NSDate date] dateByAddingTimeInterval:48*60*60], but in my case I need to support it even if app is not running :-(

Please suggest.

Was it helpful?

Solution

The answer is that you can't, I've already faced this problem and I was really disappointed about it. Actually I've solved (somehow) rescheduling the local notification each time the app is open. My solution is based on the hypothesis that the user will use the app during the interval between the first notif and the last

  • I create an amount of notifications (the limit is 64per app), usually 10
  • when the user open the app I reschedule them, but keeping always the same amount. Let's say that 3 are already fired, I reschedule just the 3 fired
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top