如何让本地通知只触发一次?

How to make local notification fire only once?

我正在尝试将 swift 中的本地通知设置为在特定日期触发一次,但似乎没有重复间隔这样的选项。默认情况下,它每 24 小时触发一次。有没有什么方法可以提交只触发一次的通知,这样用户甚至不必打开应用程序等等?

您必须将 UILocalNotificationrepeatInterval 设置为 0:

If you assign a calendar unit such as weekly (NSCalendarUnitWeekOfYear) or yearly (NSCalendarUnitYear), the system reschedules the notification for delivery at the specified interval. Note that intervals of less than one minute are not supported.

The default value is 0, which means that the system fires the notification once and then discards it.

关于你的第二个问题:没有!用户必须至少打开应用程序一次!否则,应用程序不会执行其任何代码。在首次启动时注册通知。