Reputation: 2461
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!
Upvotes: 0
Views: 287
Reputation: 272
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 .
}
}
Upvotes: 0
Reputation: 1776
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.
Upvotes: 1
Reputation: 1051
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];
Upvotes: 1