首页 > 解决方案 > 我想在一周中的特定日子发送通知

问题描述

我只想在周一、周二、周三、周四和周五上午 11:55 发送本地通知。我找不到详细的来源。你能帮助我吗?

标签: swift

解决方案


您可以使用UNCalendarNotificationTrigger和创建触发器。您可以设置日期、时区、年、月、日、小时、分钟以及是否需要重复。接下来,创建一个请求UNNotificationRequest,并完成将请求添加到通知中心。

像这样:

import UserNotifications

let trigger = UNCalendarNotificationTrigger(dateMatching: DateComponents(calendar: Calendar.current, timeZone: Calendar.current.timeZone, year: 2019, month: 1, day: 14, hour: 11, minute: 55, repeats: true )
            let request = UNNotificationRequest(identifier: "identifier", content: content, trigger: trigger)
            UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

您只能创建(计划)64 个本地通知


推荐阅读