gpt4 book ai didi

ios - 重复本地通知会删除之前待处理的本地通知

转载 作者:行者123 更新时间:2023-11-30 11:16:12 25 4
gpt4 key购买 nike

我想每 30 分钟后发送一次本地通知。我已经实现了重复本地通知,但它删除了前面的本地通知。场景解释如下:我的客户想要获得夜间警报。他希望早上醒来时可以立即查看所有通知提醒。

这是代码:

func application(_ application: UIApplication,  didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound], completionHandler: {didAllow,error in })
return true
}
func applicationDidEnterBackground(_ application: UIApplication) {
let content = UNMutableNotificationContent()
content.title = "Hello"
content.subtitle = "I am your local notification"
content.body = "Yippppiiiieee...."
content.badge = 1
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)
let request = UNNotificationRequest(identifier: "testing", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

}

最佳答案

首先,您不应使用相同的标识符,因为它会删除已安排的标识符

 let request = UNNotificationRequest(identifier: "testing", content: content, trigger: trigger)

其次你必须插入不同的TimeInterval

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)

//

(1...10).forEach {

let content = UNMutableNotificationContent()
content.title = "Hello \($0)"
content.subtitle = "I am your local notification \($0)"
content.body = "Yippppiiiieee.... \($0)"
content.badge = 1
let trigger = UNTimeIntervalNotificationTrigger(timeInterval:TimeInterval($0*1800), repeats: false)
let request = UNNotificationRequest(identifier: "testing\($0)", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

}

关于ios - 重复本地通知会删除之前待处理的本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51721396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com