我使用下面的代码创建本地通知,问题是新通知会覆盖最后一个:
let content = UNMutableNotificationContent()
content.title = userInfo["title"] as! String
content.body = userInfo["message"] as! String
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "TestIdentifier", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
如何避免这种情况?
答案 0 :(得分:0)
只需为每个通知设置不同的values_list <- values_list %>% group_by(Cells2) %>% mutate(shape = factor(seq_along(values)))
ggplot() +
geom_col(data = Mean_list, aes(Cells, Mean, fill = Cells)) +
geom_point(data = values_list, aes(Cells2, values, shape = shape))
。每次都会自动创建新的本地通知。
请使用下面的示例代码随机生成通知标识符。
identifier:
现在,使用以下代码创建本地通知。
extension NSObject {
func randomNumber() -> Int {
let randomNumber = Int(arc4random_uniform(UInt32(INT_MAX)))
return randomNumber
}
}
答案 1 :(得分:0)
在通知标识符中添加时间戳,例如遵循此代码。
让时间戳= NSDate()。timeIntervalSince1970
let content = UNMutableNotificationContent()
content.title = userInfo["title"] as! String
content.body = userInfo["message"] as! String
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let timestamp = NSDate().timeIntervalSince1970
let request = UNNotificationRequest(identifier: "TestIdentifier\(Int(timestamp))", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)