我想每 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)
}