func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
if response.notification.request.content.categoryIdentifier == "TIMER_EXPIRED" {
// Handle the actions for the expired timer.
if response.actionIdentifier == "SNOOZE_ACTION" {
// Invalidate the old timer and create a new one. . .
}
else if response.actionIdentifier == "STOP_ACTION" {
// Invalidate the timer. . .
}
}
// Else handle actions for other notification types. . .
}
0
您可以根据时间,日历或位置触发通知 . 触发器可以重复:
let date = Date(timeIntervalSinceNow: 60)
let triggerMinute = Calendar.current.dateComponents([.minute,.second], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerMinute, repeats: true)
2 回答
我找到了这个:
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html#//apple_ref/doc/uid/TP40008194-CH5-SW1
您可以尝试为UNNotificationResponse定义类别,然后处理响应取决于类别类型 .
您可以根据时间,日历或位置触发通知 . 触发器可以重复:
此代码尝试安排通知,使得日期的分钟和秒组件匹配,您可以按照您想要的方式对其进行配置 .