既然TimeTrigger不能用,那么就得另尋他法。在Notification命名空間下有這么一個類:ScheduledToastNotification,它的構造函數是這樣的:
public:
ScheduledToastNotification(
XmlDocument^ content,
DateTime deliveryTime
)
該構造函數構造一個定時的Toast消息,并且只顯示一次。
有了該方法,定時推送就比較簡單了,只要在你的代碼中實現以下代碼:
Windows::Globalization::Calendar^ cal = ref new Windows::Globalization::Calendar();
cal->AddMinutes(1);
Windows::Foundation::DateTime dateToFormat = cal->GetDateTime();
ToastTemplateType toastTemplate = ToastTemplateType::ToastText01;
XmlDocument^ toastXml = ToastNotificationManager::GetTemplateContent(toastTemplate);
XmlNodeList^ toastTextElements = toastXml->GetElementsByTagName("text");
toastTextElements->Item(0)->InnerText = "You need to do a work!";
auto notification = ref new ScheduledToastNotification(toastXml, dateToFormat);
ToastNotificationManager::CreateToastNotifier()->AddToSchedule(notification);
cal->AddMinutes(1);
Windows::Foundation::DateTime dateToFormat = cal->GetDateTime();
ToastTemplateType toastTemplate = ToastTemplateType::ToastText01;
XmlDocument^ toastXml = ToastNotificationManager::GetTemplateContent(toastTemplate);
XmlNodeList^ toastTextElements = toastXml->GetElementsByTagName("text");
toastTextElements->Item(0)->InnerText = "You need to do a work!";
auto notification = ref new ScheduledToastNotification(toastXml, dateToFormat);
ToastNotificationManager::CreateToastNotifier()->AddToSchedule(notification);
這里DateTime是個結構體類型,我們只能通過Calender對象來獲取時間,因為我們最后建立的是一個ScheduledToastNotification類型的Toast,所以最后要哦那個AddToShedule來顯示出來。