我们可以同时为 3 个项目触发多个 uilocalnotification,例如:当应用程序处于后台/前台时,通知设置为下午 5:00 触发..我应该收到 3 个通知应该一个接一个触发。它只会触发最后设置的通知。我已经添加了代码。
- (UILocalNotification *)scheduleNotification :(int)remedyID
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil)
{
NSString *descriptionBody;
NSInteger frequency;
UILocalNotification *notif = [[cls alloc] init];
notif.timeZone = [NSTimeZone defaultTimeZone];
for (int i=0; i<remedyArray.count; i++)
{
int arrayid = [[[remedyArray objectAtIndex:i] objectForKey:@"RemedyID"] intValue];
if (arrayid == remedyID)
{
descriptionBody=[[remedyArray objectAtIndex:i] objectForKey:@"RemedyTxtDic"];
frequency=[[[remedyArray objectAtIndex:i] objectForKey:@"RemedyFrequency"] integerValue];
break;
}
}
NSArray *notificationFireDates = [self fireDatesForFrequency:frequency];
for (NSDate *fireDate in notificationFireDates)
{
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil)
{
UILocalNotification *notif = [[cls alloc] init];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.repeatInterval = NSDayCalendarUnit;
notif.alertBody = [NSString stringWithString:descriptionBody];
notif.alertAction = @"Show me";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;
notif.fireDate = fireDate;
NSDictionary *userDict = [NSDictionary dictionaryWithObject:notif.alertBody
forKey:@"kRemindMeNotificationDataKey"];
notif.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
}
}
return notif;
}
else
{
return nil;
}
}