gpt4 book ai didi

ios - NSLocal 通知重复循环报警

转载 作者:行者123 更新时间:2023-11-28 22:32:52 31 4
gpt4 key购买 nike

我正在使用闹钟应用程序。我正在使用 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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com