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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…