How to repeat UILocalNotification daily at 5 pm ? Following is my code to set custom time. But i want to notify the user daily at custom or may be static time. I am using iOS 6.
-(void)scheduleNotification{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"h:mm a"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:timeStr];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = dateFromString;
localNotif.repeatInterval = kCFCalendarUnitDay;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotif.alertBody = @"Reminder is set";
// Set the action button
localNotif.alertAction = @"Ok";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Local Push received while running", @"key", nil];
localNotif.userInfo = infoDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
Here's my solution, utilizing NSCalendar:
Use this. It may help you