繁体   English   中英

如何同时触发多个通知?

[英]How to fire multiple notification at the same time?

我们是否可以同时触发3个项目的多个uilocalnotification语句,例如:当应用程序处于后台/前景时,通知设置为在5:00 pm触发。我应该收到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;
        }

    }

如果您要说的是这样调用代码:

   [something scheduleNotification:remedyOne];
   [something scheduleNotification:remedyTwo];
   [something scheduleNotification:remedyThree];

然后,重写您的代码。 因为你的代码有

[[UIApplication sharedApplication] cancelAllLocalNotifications];

scheduleNotification的第一行方法。

这就是问题所在。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM