gpt4 book ai didi

ios - UILocalNotification 已触发但未安排

转载 作者:行者123 更新时间:2023-11-29 12:25:38 32 4
gpt4 key购买 nike

大家好,我的应用程序有问题,我想在其中添加一些基本的 LocalNotifications,这些通知每周都会重复。我想在名为“scheduleLocalNotificationForItem:”的方法中执行此操作,该方法在按下 doneBarButtonItem 时调用。到目前为止,这一切似乎都有效,因为当我记录所有预定通知时,每个预定通知都会显示出来。但是当我使用该应用程序时,预定的通知会被触发并显示,但还有一些额外的通知,我没有自己设置,我无法确定它们来自哪里,它们也会出现。

这是我的代码:

- (int)scheduleNotifitactionsForItem:(AlarmItem *)item
{
NSArray *reorderdRepeat = [NSArray arrayWithArray:[self transformArray:item.repeat]];
int missedDays = 0;
int scheduledAlarms = 0;
for (int i = 0; i < item.repeat.count; i++) {
if ([[reorderdRepeat objectAtIndex:i] boolValue] == true) {//Problem determinating true values at end of array
NSInteger integerOfDay = i + 1;//reorderRepeat should contain seven items, icrement i bevore adding it to integerOfDay
NSDate *lastAlarmTime = [self getFireDateForDayOfWeek:integerOfDay withTime:item.time];
NSArray *allAlramTimesForDay = [self getFireDatesForTime:lastAlarmTime andCycle:item.cycles];
for (int i = 0; i < allAlramTimesForDay.count; i++) {
NSDate *alarmTime = [allAlramTimesForDay objectAtIndex:i];
UIApplication *application = [UIApplication sharedApplication];
UILocalNotification *notification = [UILocalNotification new];
NSDictionary *userInfo = @{@"index":[NSString stringWithFormat:@"%d",item.notification]};
notification.repeatInterval = NSCalendarUnitWeekday;
notification.alertBody = item.title;
notification.userInfo = userInfo;
notification.fireDate = alarmTime;
notification.soundName = item.sound;
[application scheduleLocalNotification:notification];
scheduledAlarms += 1;
}
} else {
missedDays += 1;
}
}
return scheduledAlarms;
}

感谢帮助;)

最佳答案

您的repeatInterval 应该是NSCalendarUnitWeekOfYear(或旧的NSWeekCalendarUnit)。 NSCalendarUnitWeekday (NSWeekdayCalendarUnit) 每天都会重复。

关于ios - UILocalNotification 已触发但未安排,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29250744/

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