0

I have to fire UILocalNotification according to particular day with hours and minutes but don't have date. E.g. I have to fire UILocalNotification on every "Mon 02:30 PM". How can I set local notification like this?

Please suggest me.

Thanks!

Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189
Sudha Tiwari
  • 2,499
  • 26
  • 50

3 Answers3

1

You can set the UILocalNotification's repeatInterval to NSCalendarUnitWeekday

  if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
      UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];
      [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  }  else {
      UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
      [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
  }

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

  NSDate *currentDate   = [NSDate date];

  notification.fireDate = [currentDate dateByAddingTimeInterval:10.0];

  notification.repeatInterval = NSCalendarUnitWeekday;

  notification.alertBody   = @"Wake up, man";
  notification.soundName= UILocalNotificationDefaultSoundName;

  notification.applicationIconBadgeNumber++;

  [[UIApplication sharedApplication] scheduleLocalNotification:notification];
酷酷的哀殿
  • 1,021
  • 6
  • 18
1

Get the next monday date from current date.For that follow this Link Next Monday Date

After that set notification for it and set the repeat interval to NSCalendarUnitWeekOfYear so the notification will trigger every monday.

Community
  • 1
  • 1
Muneeba
  • 1,756
  • 10
  • 11
0

You get the system date and time, and use that to set your logic.

In pseudocode:

if today == monday {

    if time == 2:30 PM {

        fire local notification .
    }
}
Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189
vikash1307
  • 272
  • 2
  • 12