選擇通知傳遞方法Choose a notification delivery method

本文涵蓋四個通知選項:本機、排程、定期和推播,它們會傳遞磚和徽章更新及快顯通知內容。This article covers the four notification options—local, scheduled, periodic, and push—that deliver tile and badge updates and toast notification content. 即使使用者沒有與應用程式直接互動,磚或快顯通知仍然可以將資訊傳遞給使用者。A tile or a toast notification can get information to your user even when the user is not directly engaged with your app. App 的性質及內容與您想傳遞的資訊,可以協助您判斷哪種通知方法最適合您的案例。The nature and content of your app and the information that you want to deliver can help you determine which notification method or methods is best for your scenario.

通知傳遞方法概觀Notification delivery methods overview

App 可以使用四種機制來傳遞通知:There are four mechanisms that an app can use to deliver a notification:

  • 本機Local
  • 排程Scheduled
  • 定期Periodic
  • 推送Push

下表摘要說明通知傳遞類型。This table summarizes the notification delivery types.

傳遞方法Delivery method 搭配使用項目Use with 描述Description 範例Examples
本機Local 磚、徽章、快顯通知Tile, Badge, Toast 在 App 執行時傳送通知的一組 API 呼叫,會直接更新磚或徽章,或傳送快顯通知。A set of API calls that send notifications while your app is running, directly updating the tile or badge, or sending a toast notification.
  • 音樂 App 會更新磚以顯示「現正播放」""的內容。A music app updates its tile to show what's "Now Playing".
  • 遊戲 App 在使用者離開遊戲時,會以使用者的最高分數來更新磚。A game app updates its tile with the user's high score when the user leaves the game.
  • 啟動 app 時,便會清除其字符指出 app 有新資訊的徽章。A badge whose glyph indicates that there's new info int the app is cleared when the app is activated.
已排程Scheduled 磚、快顯通知Tile, Toast 預先排程通知以在您指定的時間更新的一組 API 呼叫。A set of API calls that schedule a notification in advance, to update at the time you specify.
  • 行事曆應用程式會為即將發生的會議設定快顯通知提醒。A calendar app sets a toast notification reminder for an upcoming meeting.
定期Periodic 磚、徽章Tile, Badge 透過輪詢雲端服務來取得新內容,並以固定時間間隔來定期更新磚與徽章的通知。Notifications that update tiles and badges regularly at a fixed time interval by polling a cloud service for new content.
  • 氣象 App 每 30 分鐘會更新一次顯示氣象預測的磚。A weather app updates its tile, which shows the forecast, at 30-minute intervals.
  • 「每日特賣」""網站會在每天早上更新當日的特價商品。A "daily deals" site updates its deal-of-the-day every morning.
  • 顯示事件倒數天數的磚會在每日午夜更新顯示的倒數天數。A tile that displays the days until an event updates the displayed countdown each day at midnight.
推送Push 磚、徽章、快顯通知、原始通知Tile, Badge, Toast, Raw 即使您的應用程式未執行,仍然會從雲端伺服器傳送的通知。Notifications sent from a cloud server, even if your app isn't running.
  • 購物應用程式會傳送快顯通知,讓使用者知道他們所追蹤物品的拍賣活動。A shopping app sends a toast notification to let a user know about a sale on an item that they're watching.
  • 新聞應用程式會在發生突發新聞時更新磚。A news app updates its tile with breaking news as it happens.
  • 運動應用程式會隨時以即時賽況來更新磚。A sports app keeps its tile up-to-date during an ongoing game.
  • 通訊應用程式會提供關於內送郵件或電話的警示。A communication app provides alerts about incoming messages or phone calls.

本機通知Local notifications

在應用程式執行時更新應用程式磚或徽章,或是產生快顯通知,是最簡單的通知傳遞機制;它只需要本機 API 呼叫。Updating the app tile or badge or raising a toast notification while the app is running is the simplest of the notification delivery mechanisms; it only requires local API calls. 每個應用程式都可以在磚上顯示實用或有趣的資訊,即使該內容只會在使用者啟動並與應用程式互動時才變更。Every app can have useful or interesting information to show on the tile, even if that content only changes after the user launches and interacts with the app. 即使您也使用了其他的通知機制,本機通知還是讓應用程式磚保持最新狀態的好辦法。Local notifications are also a good way to keep the app tile current, even if you also use one of the other notification mechanisms. 例如,相片應用程式磚可以顯示最近新增相簿中的相片。For instance, a photo app tile could show photos from a recently added album.

我們建議第一次啟動您的應用程式時在本機更新它的磚,或者至少在使用者進行變更之後立即更新磚 (您的應用程式正常會在磚做出的反映)。We recommended that your app update its tile locally on first launch, or at least immediately after the user makes a change that your app would normally reflect on the tile. 該更新要等到使用者離開應用程式才能顯示,但在應用程式使用期間進行此變更,可確保使用者離開時磚已經更新為最新資訊。That update isn't seen until the user leaves the app, but by making that change while the app is being used ensures that the tile is already up-to-date when the user departs.

當 API 呼叫是本機呼叫時,通知可以參考網頁影像。While the API calls are local, the notifications can reference web images. 如果網路影像無法下載、已損毀或不符合影像規格,磚與快顯通知的應對方式是不同的:If the web image is not available for download, is corrupted, or doesn't meet the image specifications, tiles and toast respond differently:

  • 磚:不會顯示更新Tiles: The update is not shown
  • 快顯通知:會顯示通知,但是捨棄影像Toast: The notification is displayed, but your image is dropped

根據預設,本機快顯通知會在三天後到期,而本機磚通知永遠不會過期。By default, local toast notifications expire in three days, and local tile notifications never expire. 我們建議針對您的通知使用合理且明確的到期時間 (快顯通知的最大值為三天) 來覆寫這些預設值。We recommend overriding these defaults with an explicit expiration time that makes sense for your notifications (toasts have a max of three days).

如需詳細資訊,請參閱下列主題:For more information, see these topics:

排程通知Scheduled notifications

排程通知是本機通知的子集,它們可以指定應該更新磚或顯示快顯通知的確切時間。Scheduled notifications are the subset of local notifications that can specify the precise time when a tile should be updated or a toast notification should be shown. 排程通知適合事先已知道要更新之內容 (像是會議邀請) 的情況。Scheduled notifications are ideal in situations where the content to be updated is known in advance, such as a meeting invitation. 如果您事先並不清楚通知內容,那就應該使用推播或定期通知。If you don't have advance knowledge of the notification content, you should use a push or periodic notification.

請注意,排程的通知無法用於徽章通知;徽章通知最適合當作本機、定期或推播通知。Note that scheduled notifications cannot be used for badge notifications; badge notifications are best served by local, periodic, or push notifications.

根據預設,排程的通知會在傳遞的三天後到期。By default, scheduled notifications expire three days from the time they are delivered. 您可以覆寫排程的磚通知上的這個預設到期時間,但無法覆寫排程的快顯通知上的到期時間。You can override this default expiration time on scheduled tile notifications, but you cannot override the expiration time on scheduled toasts.

如需詳細資訊,請參閱下列主題:For more information, see these topics:

定期通知Periodic notifications

定期通知可以讓您使用最少的雲端服務與用戶端投資設備來提供動態磚更新。Periodic notifications give you live tile updates with a minimal cloud service and client investment. 它們也是將相同內容散佈給廣大群眾的絕佳方式。They are also an excellent method of distributing the same content to a wide audience. 您的用戶端程式碼可以指定雲端位置 URL,好讓 Windows 輪詢以取得磚或徽章的更新,以及指定輪詢該位置的頻率。Your client code specifies the URL of a cloud location that Windows polls for tile or badge updates, and how often the location should be polled. Windows 會在每個輪詢間隔期間連線 URL,下載指定的 XML 內容並在磚上顯示內容。At each polling interval, Windows contacts the URL to download the specified XML content and display it on the tile.

應用程式必須裝載雲端服務才能使用定期通知,而所有已安裝應用程式的使用者將以指定的間隔輪詢這項服務。Periodic notifications require the app to host a cloud service, and this service will be polled at the specified interval by all users who have the app installed. 請注意,定期更新無法用於快顯通知;快顯通知適合排程或推播通知。Note that periodic updates cannot be used for toast notifications; toast notifications are best served by scheduled or push notifications.

根據預設,定期通知會在輪詢發生的三天後到期。By default, periodic notifications expire three days from the time polling occurs. 如有需要,您可以指定明確的到期時間來覆寫這個預設設定。If needed, you can override this default with an explicit expiration time.

如需詳細資訊,請參閱下列主題:For more information, see these topics:

推送通知Push notifications

若要交流即時資料或針對使用者個人化的資料,就非常適合使用推播通知。Push notifications are ideal to communicate real-time data or data that is personalized for your user. 推播通知用於在無法預測的時間產生的內容,像是突發新聞、社交網路更新或立即訊息。Push notifications are used for content that is generated at unpredictable times, such as breaking news, social network updates, or instant messages. 當資料 (像是遊戲進行時的遊戲分數) 有時效性而不適合定期通知時,也可以使用推播通知。Push notifications are also useful in situations where the data is time-sensitive in a way that would not suit periodic notifications, such as sports scores during a game.

推播通知需要能夠管理推播通知通道與選擇何時將通知傳送給何人的雲端服務。Push notifications require a cloud service that manages push notification channels and chooses when and to whom to send notifications.

根據預設,推播通知會在裝置收到的三天後到期。By default, push notifications expire three days from the time they are received by the device. 如有需要,您可以指定明確的到期時間來覆寫這個預設值 (快顯通知的最大值為三天)。If needed, you can override this default with an explicit expiration time (toasts have a max of three days).

如需詳細資訊,請參閱For more information, see: