[英]UILocalNotification triggered but not scheduled
嗨,大家好,我的應用程序有問題,我想在其中添加一些基本的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
)將每天重復一次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.