在本地通知中设置repeatInterval [英] Set repeatInterval in local notification

查看:255
本文介绍了在本地通知中设置repeatInterval的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将重复间隔设置为用户从日期选择器中选择的值。我的应用程序中有日期选择器,类型为倒计时模式。如果用户从日期选择器中选择4小时15分钟,那么我使用以下代码设置并且报警响铃。

  [NSDate dateWithTimeIntervalSinceNow:[pickerTimer countDownDuration]] 
pre>

但是,我希望每4小时15分钟后再重复一次通知,直到用户取消该通知。我已经搜索了很多,但我无法确定。迄今为止使用的代码是:

  localNotification = [[UILocalNotification alloc] init]; 
[localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:[pickerTimer countDownDuration]]];

if(localNotification.fireDate){

[self _showAlert:@Time is scheduledwithTitle:@Daily Achiever];
}
localNotification.timeZone = [NSTimeZone systemTimeZone];


localNotification.alertBody = @alaram;
localNotification.soundName = UILocalNotificationDefaultSoundName;
[localNotification setAlertAction:@View];
[localNotification setRepeatInterval:[pickerTimer countDownDuration]];

//启动应用程序并显示在警报中的按钮文本
// [localNotification setAlertBody:[alertBodyField text]]; //从textField的文本中的通知中设置消息
// [localNotification setHasAction:YES]; //设置按下按钮将启动应用程序
[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]]; //将应用程序图标的应用程序图标号码设置为当前应用程序图标徽章号码加$ 1

localNotification.applicationIconBadgeNumber = 1;

localNotification.repeatInterval = NSHourCalendarUnit;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //使用系统计划通知

// [alertNotification setHidden:NO]; //设置alertNotification以显示用户应用程序已注册本地通知

请帮助我来解决非常感谢。

解决方案

我们无法为 repeatInterval UILocalNotification



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



其他方法是在处理本地通知时更改 burningate


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 the UILocalNotification.

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.

这篇关于在本地通知中设置repeatInterval的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆