我正在使用Alarm App。我使用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];
任何人帮助我。
答案 0 :(得分: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];
.....
....
...
您需要多少次。你可以重复创作。