簡體   English   中英

如何在收到推入通知時啟動/恢復Windows Phone 8.1 C#應用程序

[英]How to start/resume Windows Phone 8.1 C# app upon incoming push notification

我正在WP 8.1上開發Windows試用版應用程序,該應用程序必須在傳入的推送通知中向用戶顯示一些覆蓋(或至少顯示MessageDialog)。

下面的代碼顯示了當應用程序處於前台且吐司即將到來時的消息,但是無論在后台運行還是根本沒有啟動應用程序時,我都找不到如何啟動/恢復/執行任何操作的信息或手機已鎖定。 我在控制台日志中看到的Atm,當應用程序進入后台時仍會收到吐司,但沒有出現UI消息。

我有的:

ToastCapable="true"

在一些xaml.cs文件中:

init() {
    PushNotificationChannel channel 
        = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
    channel.PushNotificationReceived += OnPushNotificationReceived;
}

void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e) {
    Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
        showToTheUser();
    });
}

private async void showToTheUser() {
    // TODO message to be replaced with full-screen overlay later

    var messageDialog = new MessageDialog("Incoming push");

    messageDialog.Commands.Add(new UICommand(
        "Accept",
        new UICommandInvokedHandler(this.CommandInvokedHandler)));
    messageDialog.Commands.Add(new UICommand(
        "Refuse",
        new UICommandInvokedHandler(this.CommandInvokedHandler)));

    messageDialog.DefaultCommandIndex = 0;
    messageDialog.CancelCommandIndex = 1;

    await messageDialog.ShowAsync();
}

private void CommandInvokedHandler(IUICommand command) {
    if (command.Label.Equals("Accept")) {
        // show some UI page of the app
    }
}

我是一個經驗豐富的Java專家,剛開始使用WP和C#,所以我很困惑在WP上應該做的正確方法或應該尋找的東西。

如果我對您的理解正確,則希望基於推送通知啟動應用程序並顯示信息。Windows Phone上無法做到這一點。 用戶可以單擊通知橫幅並打開應用程序,但是您不能自動執行該操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM