共用方式為


PushNotificationChannelManager.ChannelsRevoked 事件

定義

當您的推播通道遭到撤銷時引發,以便您可以立即要求新的通道。 這可將使用撤銷的 WNS 通道所產生的任何停機時間降到最低。 事件引數類型為 PushNotificationChannelsRevokedEventArgs

// Register
static event_token ChannelsRevoked(EventHandler<PushNotificationChannelsRevokedEventArgs> const& handler) const;

// Revoke with event_token
static void ChannelsRevoked(event_token const* cookie) const;

// Revoke with event_revoker
static PushNotificationChannelManager::ChannelsRevoked_revoker ChannelsRevoked(auto_revoke_t, EventHandler<PushNotificationChannelsRevokedEventArgs> const& handler) const;
public static event System.EventHandler<PushNotificationChannelsRevokedEventArgs> ChannelsRevoked;
function onChannelsRevoked(eventArgs) { /* Your code */ }
Windows.Networking.PushNotifications.PushNotificationChannelManager.addEventListener("channelsrevoked", onChannelsRevoked);
Windows.Networking.PushNotifications.PushNotificationChannelManager.removeEventListener("channelsrevoked", onChannelsRevoked);
- or -
Windows.Networking.PushNotifications.PushNotificationChannelManager.onchannelsrevoked = onChannelsRevoked;
Public Shared Custom Event ChannelsRevoked As EventHandler(Of PushNotificationChannelsRevokedEventArgs) 

事件類型

Windows 需求

裝置系列
Windows 10, version 2004 (已於 10.0.19041.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v10.0 引進)

範例

// Create the manager, and subscribe to the ChannelsRevoked event.

PushNotificationChannel channel = null;
PushNotificationChannelManager.ChannelsRevoked += OnChannelsRevoked;

try
{
    // Create the channel manager for the user.
    PushNotificationChannelManagerForUser channelManagerForUser = PushNotificationChannelManager.GetDefault();

    // Create the channel.
    channel = await channelManagerForUser.CreatePushNotificationChannelForApplicationAsync();

    // If the channel isn't null, send to app service.
    if (channel != null)
    {
        sendChannelURIToServer(channel.Uri);
    }
}
catch (Exception e){ ... }

...

private async void OnChannelsRevoked(PushNotificationChannelsRevokedEventArgs e)
{
    // PushNotificationChannelsRevokedEventArgs has no members.
    // Previous channel was revoked, time to create a new channel as shown above.
    ...
}    

備註

您可以建立推播通道,以透過 WNS 接收來自服務的推播通知。 這些通道不是永久的,而且可能會因為各種原因而變更, (通道在三十天后過期) 最常見的原因。 此外,平臺也會發生事件,例如,全域裝置識別碼會變更) ,以撤銷通道 (。 但是,如果您使用此事件,則每次應用程式啟動時都不需要要求新的通道。

適用於