알림 메시지를 예약하는 방법(HTML)

[ 이 문서는 Windows 런타임 앱을 작성하는 Windows에서 8.x 및 Windows Phone 8.x 개발자를 대상으로 합니다. Windows 10용으로 개발하는 경우에는 최신 설명서를 참조하세요.]

참고  JavaScript를 사용하지 않는 경우 알림 메시지를 예약하는 방법(XAML)을 참조하세요.

 

이 항목에서는 알림 메시지가 정해진 시간에 표시되도록 예약하는 방법을 보여 줍니다.

알아야 할 사항

기술

  • Windows Runtime

사전 요구 사항

지침

단계 1: 템플릿 지정

전달 시간을 지정하려면 먼저 알림을 만들어야 합니다.


var template = Windows.UI.Notifications.ToastTemplateType.toastText02;                        
var toastXml = Windows.UI.Notifications.ToastNotificationManager.getTemplateContent(template);

단계 2: 알림 메시지 콘텐츠 제공

이 내용은 예약된 알림과 예약되지 않은 알림에서 동일하므로 여기에서 다루지 않습니다. 자세한 내용은 빠른 시작: 알림 메시지 보내기를 참조하세요.

단계 3: 알림 메시지 전달 시간 지정

이 예에서는 알림이 3초 후에 표시되도록 지정합니다. 이 예에서는 JavaScript Date 개체를 사용하여 현재 시간을 검색합니다.


var currentTime = new Date();
var startTime = new Date(currentTime.getTime() + 3 * 1000);

단계 4: 예약된 알림 메시지 개체 만들기

알림 메시지 콘텐츠 및 예약된 전달 시간을 생성자에 보냅니다.

var scheduledToast = new Windows.UI.Notifications.ScheduledToastNotification(toastXml, startTime);

단계 5: 옵션: 예약된 알림 메시지에 ID 지정

이 ID는 16자 이하여야 합니다. 나중에 알림을 취소하려는 경우에 사용할 수 있습니다.

scheduledToast.id = "Future_Toast";

단계 6: 일정에 알림 메시지를 추가합니다.

ToastNotifier 개체를 만듭니다. 이 개체는 일정에 알림을 추가하는 데 사용됩니다.


var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.createToastNotifier();
toastNotifier.addToSchedule(scheduledToast);

정해진 간격마다 반복되는 알림 메시지 추가

다음 코드는 각각 1분 간격으로 단일 알림 메시지를 5회 표시합니다. 쉽게 읽을 수 있도록 템플릿을 채우는 코드는 생략됩니다.


var template = Windows.UI.Notifications.ToastTemplateType.toastText02;
var toastXml = Windows.UI.Notifications.ToastNotificationManager.getTemplateContent(template);

// TO DO: Fill in the template with your notification content here. 
 
var currentTime = new Date();
var startTime = new Date(currentTime.getTime() + 1000);
 
var recurringToast = new Windows.UI.Notifications.ScheduledToastNotification(toastXml, startTime, 60 * 1000, 5);
recurringToast.id = "Recurring_Toast";

var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.createToastNotifier();
toastNotifier.addToSchedule(recurringToast);