I want to set repeat interval to the value which user selects from date picker.I have date picker of type countdown mode in my application.If user selects 4 hours 15 minutes from date picker then I am setting firedate using the following code and alarm rings.
[NSDate dateWithTimeIntervalSinceNow:[pickerTimer countDownDuration]]
But I want that notification should repeat after every 4 hours 15 minutes until user cancels it. I have done r&d searched a lot but I can not figure out.The code I have used so far is:
localNotification = [[UILocalNotification alloc] init];
[localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:[pickerTimer countDownDuration]]];
if(localNotification.fireDate){
[self _showAlert:@"Time is scheduled" withTitle:@"Daily Achiever"];
}
localNotification.timeZone = [NSTimeZone systemTimeZone];
localNotification.alertBody=@"alaram";
localNotification.soundName = UILocalNotificationDefaultSoundName;
[localNotification setAlertAction:@"View"];
[localNotification setRepeatInterval:[pickerTimer countDownDuration]];
//The button's text that launches the application and is shown in the alert
// [localNotification setAlertBody:[alertBodyField text]]; //Set the message in the notification from the textField's text
//[localNotification setHasAction: YES]; //Set that pushing the button will launch the application
[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1
localNotification.applicationIconBadgeNumber = 1;
localNotification.repeatInterval=NSHourCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system
//[alertNotification setHidden:NO]; //Set the alertNotification to be shown showing the user that the application has registered the local notification
Please help me to solve. Thanks a lot in advance.
We cannot set custom Value for
repeatInterval
in theUILocalNotification
.The simplest way you can achieve this by creating a new
localNotification
every 4.25 hours and copy the notification details of the the the existing one and delete it while handling the local notification.Other way is to change the
firedate
while handling the local notification.I have solved the problem using following code:
Here testDate and refTimeInterval are variables declared in .pch file.