如何:发送预定通知How To: Send scheduled notifications

如果在你的方案中,需要在将来的某个时间点发送通知,但却无法轻松地唤醒后端代码来发送该通知。If you have a scenario in which you want to send a notification at some point in the future, but do not have an easy way to wake up your back-end code to send the notification. 标准层通知中心支持安排最多未来 7 天的通知。Standard tier notification hubs support a feature that enables you to schedule notifications up to seven days in the future.

计划通知Schedule your notifications

发送通知时,只需如以下示例中所示,使用通知中心 SDK 中的 ScheduledNotificationWhen sending a notification, simply use the ScheduledNotification class in the Notification Hubs SDK as shown in the following example:

Notification notification = new AppleNotification("{\"aps\":{\"alert\":\"Happy birthday!\"}}");
var scheduled = await hub.ScheduleNotificationAsync(notification, new DateTime(2014, 7, 19, 0, 0, 0));

取消预定通知Cancel scheduled notifications

此外,可以使用其 notificationId 取消以前计划的通知:Also, you can cancel a previously scheduled notification using its notificationId:

await hub.CancelNotificationAsync(scheduled.ScheduledNotificationId);

可以发送的预定通知数没有限制。There are no limits on the number of scheduled notifications you can send.

后续步骤Next steps

参阅以下教程:See the following tutorials: