在本地通知中设置repeatInterval

我想设置重复时间间隔为用户从dateselect器中select的值。我在我的应用程序中有types倒计时模式的dateselect器。如果用户从dateselect器中select4小时15分钟,那么我使用下面的代码和闹铃。

[NSDate dateWithTimeIntervalSinceNow:[pickerTimer countDownDuration]] 

但是我希望通知应在每4小时15分钟后重复,直到用户取消为止。 我已经做了很多search,但是我弄不清楚。到目前为止,我使用的代码是:

 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 

请帮我解决。 非常感谢。

我用下面的代码解决了这个问题:

 -(void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif { testDate=notif.fireDate; NSLog(@"Recieved Notification %@",notif); [self playSoundWithNotification:notif]; [self _showAlert:@"Alaram" withTitle:@"Daily Achiever"]; } -(void)_showAlert:(NSString*)pushmessage withTitle:(NSString*)title { UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:pushmessage delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; if (alertView) { FocusViewController *fvc=[[FocusViewController alloc]initWithNibName:@"FocusViewController" bundle:nil]; [fvc insert:[NSDate dateWithTimeInterval:refTimeIntrval sinceDate:testDate]]; }} 

这里testDate和refTimeInterval是在.pch文件中声明的variables。

我们无法为UILocalNotification repeatInterval设置自定义值。

最简单的方法是每4.25小时创build一个新的localNotification并复制现有通知的详细信息,并在处理本地通知时将其删除。

其他方法是在处理本地通知的同时更改firedate