如何在传入推送通知时启动/恢复Windows Phone 8.1 C#app

时间:2015-06-11 09:48:06

标签: c# xaml windows-phone-8.1

我正在WP 8.1上开发一个试用版Windows Runtime应用程序,它必须在传入推送通知时向用户显示一些覆盖(或至少是MessageDialog)。

下面的代码显示了当应用程序处于前台并且即将到来时的消息,但我无法找到如何启动/恢复/执行任何应用程序,当它处于后台或可能应用程序不均匀时完全开始或手机被锁定。 Atm我在控制台日志中看到,当应用程序进入后台时仍然会收到Toast,但是没有显示UI消息。

我有什么:

appxmanifest中的

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上做这件事的正确方法或我应该搜索的内容。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您希望根据推送通知和显示信息启动应用程序..这在Windows Phone上是不可能的。用户可以单击通知横幅并打开应用程序,但您无法自动执行此操作。