Ios 如何显示多个本地通知?

Ios 如何显示多个本地通知?,ios,swift,localnotification,pushkit,Ios,Swift,Localnotification,Pushkit,我有一个消息应用程序,我正在使用VoIP通知向用户发送确认信息。每次调用PushKit委托时,我都会触发一个本地通知 当前的情况是,以前的通知将被删除,并由新的通知替换。是否有办法管理本地通知,以便用户可以在其设备中看到多个通知 这是我尝试过的代码: let notificationContent = UNMutableNotificationContent() notificationContent.title = "Title" notificationContent.subtitle =

我有一个消息应用程序,我正在使用
VoIP通知
向用户发送确认信息。每次调用
PushKit委托时,我都会触发一个本地通知

当前的情况是,以前的通知将被删除,并由新的通知替换。是否有办法管理本地通知,以便用户可以在其设备中看到多个通知

这是我尝试过的代码:

let notificationContent = UNMutableNotificationContent()
notificationContent.title = "Title"
notificationContent.subtitle = "Subtitle"
notificationContent.body = "Body"

// Add Trigger
let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.01, repeats: false)

// Create Notification Request
let notificationRequest = UNNotificationRequest(identifier: "cocoacasts_local_notification", content: notificationContent, trigger: notificationTrigger)

// Add Request to User Notification Center
UNUserNotificationCenter.current().add(notificationRequest) { (error) in
  if let error = error {
    print("Unable to Add Notification Request (\(error), \(error.localizedDescription))")
       }
  } 

注意:我不想在以后安排本地通知

使用for循环注册具有唯一标识符的多个通知

您应该更改此标识符“cocoacasts\u local\u notification”以动态重置唯一标识符

 let notification = UNMutableNotificationContent()
        let notificationTrigger = UNCalendarNotificationTrigger(dateMatching: dayComponent, repeats: true)
                        let lnMessageId:String = messageDict["Id"] as! String
                        let dayRequest = UNNotificationRequest(identifier: lnMessageId , content: notification, trigger: notificationTrigger)
                        UNUserNotificationCenter.current().add(dayRequest, withCompletionHandler: {(_ error: Error?) -> Void in
                            if error == nil
                            {
                                //print("success")
                            }
                            else
                            {
                                //print("UNUserNotificationCenter Error : \(String(describing: error?.localizedDescription))")
                            }
                        })
 let notification = UNMutableNotificationContent()
        let notificationTrigger = UNCalendarNotificationTrigger(dateMatching: dayComponent, repeats: true)
                        let lnMessageId:String = messageDict["Id"] as! String
                        let dayRequest = UNNotificationRequest(identifier: lnMessageId , content: notification, trigger: notificationTrigger)
                        UNUserNotificationCenter.current().add(dayRequest, withCompletionHandler: {(_ error: Error?) -> Void in
                            if error == nil
                            {
                                //print("success")
                            }
                            else
                            {
                                //print("UNUserNotificationCenter Error : \(String(describing: error?.localizedDescription))")
                            }
                        })