0

我正在使用警报应用程序。我正在使用 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];

任何人帮助我。

4

1 回答 1

2

检查以下答案。它的简单想法。您可以添加 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];
.....
....
...

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

于 2013-06-05T05:36:59.773 回答