Can we fire multiple uilocalnotification say for 3 items at the same time for example: when the app is in background / foreground ,the notification is set to fire at 5:00 pm ..i should receive 3 notification should fire one after the other .It is only firing the notification which was set last. I have added the code .
我们可以同时为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;
}
}
1 个解决方案
#1
0
If you're saying about calling your code like this:
如果你说要像这样调用你的代码:
[something scheduleNotification:remedyOne];
[something scheduleNotification:remedyTwo];
[something scheduleNotification:remedyThree];
Then, rewrite your code. Because your code have
然后,重写您的代码。因为你的代码有
[[UIApplication sharedApplication] cancelAllLocalNotifications];
In first line of scheduleNotification: method.
在scheduleNotification:方法的第一行。
So this is the issue.
所以这就是问题所在。
#1
0
If you're saying about calling your code like this:
如果你说要像这样调用你的代码:
[something scheduleNotification:remedyOne];
[something scheduleNotification:remedyTwo];
[something scheduleNotification:remedyThree];
Then, rewrite your code. Because your code have
然后,重写您的代码。因为你的代码有
[[UIApplication sharedApplication] cancelAllLocalNotifications];
In first line of scheduleNotification: method.
在scheduleNotification:方法的第一行。
So this is the issue.
所以这就是问题所在。