我想将重复间隔设置为用户从日期选择器中选择的值。我在我的应用程序中使用了类型倒计时模式的日期选择器。如果用户从日期选择器中选择4小时15分钟,使用下面的代码和闹铃开火。在本地通知中设置repeatInterval
[NSDate dateWithTimeIntervalSinceNow:[pickerTimer countDownDuration]]
但我希望通知应在每4小时15分钟后重复,直到用户取消为止。我已经做了[R & d搜索了很多,但我不out.The我用至今代码:
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];
[email protected]"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
请帮我解决。提前致谢。
嗨,恭喜你已经解决了你的问题。如果你不介意,你可以分享你的解决方案,因为我面临着同样的情况,我想在每天早上和晚上的一天重复两次本地通知,所以无法弄清楚如何做,请如果你能帮助我一些代码 –