2

I have schedule UILocalNotification in my application at 10:00 AM Every Day.

I have used following code for this

 NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ;

NSDateComponents *componentsForReferenceDate =

[calendar components:(NSDayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit ) fromDate:[NSDate date]];

[componentsForReferenceDate setDay:10] ;
[componentsForReferenceDate setMonth:10] ;
[componentsForReferenceDate setYear:2013] ;

NSDate *referenceDate = [calendar dateFromComponents:componentsForReferenceDate] ;

// set components for time 10:00 a.m.

NSDateComponents *componentsForFireDate =

[calendar components:(NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit ) fromDate: referenceDate];

[componentsForFireDate setHour:10] ;
[componentsForFireDate setMinute:0] ;
[componentsForFireDate setSecond:0] ;

NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];

// Create the notification

UILocalNotification *notification = [[UILocalNotification alloc]  init] ;

notification.fireDate = fireDateOfNotification ;
notification.timeZone = [NSTimeZone localTimeZone] ;
notification.alertBody = [NSString stringWithFormat: @"Good Morning! Have a great day!"] ;
notification.alertAction = @"go back";
notification.userInfo= [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Some information"] forKey:@"information"];
notification.repeatInterval = NSDayCalendarUnit ;
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notification] ;

It's working very good. but now I want to schedule UILocalNotification at Every other day and every third day. so how to do this?

ChandreshKanetiya
  • 2,414
  • 5
  • 27
  • 41
  • check it out http://stackoverflow.com/questions/18014438/repeating-a-local-notification-after-every-14-daystwo-weeks – Bharat Feb 08 '14 at 05:21

2 Answers2

3

You can not do customization of repeatTimeInterval of UILocalNotification.. there are many question as same like yours and also some days ago I had same question but i can not find any solution so please better is stop fight with it.

You must need to use repeat time interval from

Calendar Units Specify calendrical units such as day and month.

enum {
   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),
};
typedef NSUInteger NSCalendarUnit;

Above you can found from Apple's documentation. also read this question...

How to set Local Notification repeat interval to custom time interval?

For more information , you only scheduled local notification maximum 64, so be careful if may be you have planing in you mind that, you want to create multiple notification for do custom repeat time intervals..

Community
  • 1
  • 1
0

You can't do this simply with repeatInterval, because only the following intervals are available.

One of the solutions I can think of would be to set separate notifications for each day (without repeatInterval). But by doing it in this way you can stumble on 64 notifications limit.

Arek Holko
  • 8,966
  • 4
  • 28
  • 46