UNCalendarNotificationTrigger - Execute after the

2019-09-14 20:05发布

问题:

Good Morning Sirs

I know using UNCalendarNotificationTrigger this way:

var dateComponents = DateComponents()
dateComponents.hour = 10
dateComponents.minute = 30
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)

Every day at 10:30 a notice will be delivered.

My question is whether the user opens the applications or calls after that time, if the notification will be delivered anyway.

回答1:

Local notifications, once created and scheduled, have nothing to do with your app. They are placed in the hands of the system, which takes care of them from then on. That is what the User Notification Center is for.

The notification will always fire. Whether it will be "delivered" depends on what you mean by "delivered".

The user can turn off notifications, in which case there will be no visible notification alert when the notification fires. But if the user has elected to permit notification alerts and notifications in the Notification Center, the notification will be visible. This will happen if your app is not running.

If your app is running at the time the notification fires, then it is up to you to have set yourself up as a notification center delegate in order to hear about it. If you don't do this, then by default the alert will not be visible to the user.

If "the user opens the applications ... after that time", as you ask in your question, then the delivery of the notification has already happened. If the user has permitted notification alerts, the user has already seen the alert. You can consult the notification center to learn about recent notifications. But since you know that the notification fired at 10:30, if your app is launched is 10:40 all it has to do is look at the current time in order to know what has happened.