Microsoft Store Engagement Services - Dev Center Push Notifications UWP C#

一世执手 提交于 2021-02-08 11:51:24

问题


Ok, I have a simple and silly question, maybe someone could clarify for me.

In the instructions provided by Microsoft, they state "1.In your project, locate a section of code that runs during startup in which you can register your app to receive Dev Center notifications."

Now, would this be in App.xaml.cs OR in MainPage.xaml.cs

I did my work in App.xaml.cs (Correct Place)

However, it is not working

The instructions provided by Microsoft were vague. The example they provide also gives no hint of where to inject the code or which approach to use. I wish they would have given a full page example. I would at least understand where what goes without having to ask.

(Update/Self Answered: Hope this helps someone)


回答1:


I got it working!

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);

} 


来源:https://stackoverflow.com/questions/40938804/microsoft-store-engagement-services-dev-center-push-notifications-uwp-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!