【问题标题】:Microsoft Store Engagement Services - Dev Center Push Notifications UWP C#Microsoft Store Engagement Services - 开发中心推送通知 UWP C#
【发布时间】:2017-04-17 18:05:08
【问题描述】:

好的,我有一个简单而愚蠢的问题,也许有人可以为我澄清一下。

在 Microsoft 提供的说明中,他们声明“1.在您的项目中,找到在启动期间运行的一段代码,您可以在其中注册您的应用以接收开发中心通知。”

现在,这是在 App.xaml.cs 中还是在 MainPage.xaml.cs 中

我在 App.xaml.cs(正确位置)中完成了我的工作

但是,它不起作用

Microsoft 提供的说明含糊不清。他们提供的示例也没有提示在哪里注入代码或使用哪种方法。我希望他们能给出一个整页的例子。我至少可以不用问就知道发生了什么。

(更新/自我回答:希望这对某人有所帮助)

【问题讨论】:

  • 我在 App.xaml.cs 中完成了我的工作这是您在此处创建的后台任务吗?
  • 我不确定天气是使用前景还是背景,所以我使用了前景。
  • 我现在可以使用了,请参阅答案。

标签: c# xaml push-notification uwp


【解决方案1】:

我搞定了!

using Microsoft.Services.Store.Engagement;

  public App()
    {
        this.InitializeComponent();
        this.Suspending += OnSuspending;
        RegisterNotificationChannelAsync();
    }

    private async void RegisterNotificationChannelAsync()
    {
        StoreServicesEngagementManager manager = StoreServicesEngagementManager.GetDefault();
        await manager.RegisterNotificationChannelAsync();
    }

protected override void OnActivated(IActivatedEventArgs args)
{
base.OnActivated(args);

if (args is ToastNotificationActivatedEventArgs)
{
    var toastActivationArgs = args as ToastNotificationActivatedEventArgs;

    StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault();
    string originalArgs = engagementManager.ParseArgumentsAndTrackAppLaunch(
        toastActivationArgs.Argument);

} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-29
    • 2016-09-17
    • 1970-01-01
    • 2016-12-11
    • 2022-01-12
    • 1970-01-01
    • 2017-05-23
    • 1970-01-01
    相关资源
    最近更新 更多