2016-12-02 24 views
0

好吧,我有一个简单而愚蠢的问题,也许有人可以为我澄清。微软商店参与服务 - 开发中心推送通知UWP C#

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

现在,这会不会在App.xaml.cs或MainPage.xaml.cs中

我做了我在App.xaml.cs工作(正确位置)

但是,它不工作

Microsoft提供的说明含糊不清。他们提供的例子也没有提供何处注入代码或使用哪种方法。我希望他们能给出一个完整的例子。我至少会明白不需要问的地方。

(更新/自拍回答:希望这可以帮助别人)

+0

**我在App.xaml.cs中完成了我的工作**这是您在此创建的后台任务吗? – AVK

+0

我不确定天气使用前景或背景,所以我用前景。 –

+0

https://msdn.microsoft.com/windows/uwp/monetize/configure-your-app-to-receive-dev-center-notifications –

回答

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

}