ios - NSLocal 通知重复循环报警

标签 ios uilocalnotification

我正在使用闹钟应用程序。我正在使用 NSLocal 通知创建警报。警报工作正常。我的问题是我需要不间断地重复循环 Alatm。

我的代码:

 UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    [localNotification setFireDate:date];
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    [localNotification setAlertAction:@"Launch"];
    [localNotification setAlertBody:msg];

    [localNotification setHasAction: YES];
    localNotification.soundName = soundFile;

    localNotification.applicationIconBadgeNumber = 1;
    localNotification.repeatCalendar = [NSCalendar currentCalendar];
    localNotification.repeatInterval = kCFCalendarUnitSecond;
 [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

任何人都可以帮助我。

最佳答案

检查下面的答案。它的想法很简单。您可以增加 1 分钟,然后重复发送 LocalNotification。

int myInt=60;

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
[localNotification setFireDate:date];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[localNotification setAlertAction:@"Launch"];
[localNotification setAlertBody:msg];

[localNotification setHasAction: YES];
localNotification.soundName = soundFile;

localNotification.applicationIconBadgeNumber = 1;
localNotification.repeatCalendar = [NSCalendar currentCalendar];
localNotification.repeatInterval = kCFCalendarUnitSecond;

NSDate *datePlusOneMinute = [date dateByAddingTimeInterval:myInt];


UILocalNotification *localNotification1 = [[UILocalNotification alloc] init];
[localNotification1 setFireDate:datePlusOneMinute];
localNotification1.timeZone = [NSTimeZone defaultTimeZone];
[localNotification1 setAlertAction:@"Launch"];
[localNotification1 setAlertBody:msg];
[localNotification1 setHasAction: YES];

localNotification1.soundName = soundFile;
localNotification1.applicationIconBadgeNumber = 1;
localNotification1.repeatCalendar = [NSCalendar currentCalendar];
localNotification1.repeatInterval = kCFCalendarUnitSecond;

NSDate *datePlusOneMinute1 = [datePlusOneMinute dateByAddingTimeInterval:myInt];
UILocalNotification *localNotification2 = [[UILocalNotification alloc] init];
[localNotification2 setFireDate:datePlusOneMinute1];
localNotification2.timeZone = [NSTimeZone defaultTimeZone];
[localNotification2 setAlertAction:@"Launch"];
[localNotification2 setAlertBody:msg];
[localNotification2 setHasAction: YES];

localNotification2.soundName = soundFile;
localNotification2.applicationIconBadgeNumber = 1;
localNotification2.repeatCalendar = [NSCalendar currentCalendar];
localNotification2.repeatInterval = kCFCalendarUnitSecond;


 .....
   ....
  ...


[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification1];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification2];
.....
....
...

你需要多少次。您可以重复创建。

关于ios - NSLocal 通知重复循环报警,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16932015/

相关文章:

ios - 更改某些实体中某些属性的类型后如何迁移核心数据模型?

ios - 在 View 上强制使用特定的 Size Class

ios - 知道 iOS 通知是否被关闭

iphone - UILocalNotification 显示 400 个角标(Badge)

ios - 从 IOS 上传图像文件到 Web 服务器

ios - 从 tableViewCell 类获取 indexPath

ios - 如何通过一个按钮链接两个 iphone 应用程序

ios - 从 NSData 为 localNotification 设置自定义声音

ios - 发送本地推送 - 从日期到日期,以小时为间隔

ios - 在后台停止音频