2016-12-02 28 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); 

}