Свойство триггера BackgroundTaskRegistration имеет значение null

Привет, хочу получать push-уведомления о фоновой задаче, для которой я создал портативную библиотеку, вот мой класс фоновой задачи

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Windows.ApplicationModel.Background;
using Windows.Data.Xml.Dom;
using Windows.Networking.PushNotifications;
using Windows.Storage;
using Windows.UI.Notifications;

namespace BackgroundTask
{
    public sealed class NotificationTask : IBackgroundTask
    {
        public void Run(IBackgroundTaskInstance taskInstance)
        {

            // Get the background task details
            ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
            string taskName = taskInstance.Task.Name;

            Debug.WriteLine("Background " + taskName + " starting...");

            // Store the content received from the notification so it can be retrieved from the UI.
            ToastNotification notification = (ToastNotification )taskInstance.TriggerDetails;
            settings.Values[taskName] = notification.Content;
            NotificationTask.AddTostNotification(notification.Content);

            Debug.WriteLine("Background " + taskName + " completed!");
        }



    private static void AddTostNotification(String xmlDocument)
    {

        List<string> messageSection = NotificationTask.GetMessageAndLandingPage(xmlDocument, "toast");

        if (messageSection == null) { return; }

        ToastTemplateType toastTemplate = ToastTemplateType.ToastText01;

        XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
        XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
        toastTextElements[0].AppendChild(toastXml.CreateTextNode(messageSection[0]));
        //  toastTextElements[1].AppendChild(toastXml.CreateTextNode(message));

        IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
        ((XmlElement)toastNode).SetAttribute("launch", messageSection[1]);

        XmlElement audio = toastXml.CreateElement("audio");
        audio.SetAttribute("src", "ms-appx:///Assets/Play-Guitar.wav");
        //audio.SetAttribute("loop", "true");
        toastNode.AppendChild(audio);

        //launch tost immediatly
        ToastNotification toast = new ToastNotification(toastXml);
        ToastNotificationManager.CreateToastNotifier().Show(toast);

    }

Здесь я регистрирую задачу

    internal async void InitChannel()
    {

        // Applications must have lock screen privileges in order to receive raw notifications
        BackgroundAccessStatus backgroundStatus = await BackgroundExecutionManager.RequestAccessAsync();

        // Make sure the user allowed privileges
        if (backgroundStatus != BackgroundAccessStatus.Denied && backgroundStatus != BackgroundAccessStatus.Unspecified)
        {
            Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            try
            {
                var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

                if (channel != null)
                {

                    roamingSettings.Values["ExistingPushChannel"] = channel.Uri;

                    dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
                    channel.PushNotificationReceived += OnPushNotificationReceived;

                    UnregisterBackgroundTask();
                    RegisterBackgroundTask();

                }
                else
                {
                    roamingSettings.Values["ExistingPushChannel"] = "Failed to create channel";
                }
            }
            catch
            {
                roamingSettings.Values["ExistingPushChannel"] = "Failed to create channel";
            }
        }

    }
   private void RegisterBackgroundTask()
    {
        BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
        PushNotificationTrigger trigger = new PushNotificationTrigger();

        taskBuilder.SetTrigger(trigger);

        // Background tasks must live in separate DLL, and be included in the package manifest
        // Also, make sure that your main application project includes a reference to this DLL

        taskBuilder.TaskEntryPoint = "BackgroundTask.NotificationTask";
        taskBuilder.Name = "PlaypushNotification";

        try
        {
            BackgroundTaskRegistration task = taskBuilder.Register();
            task.Completed += BackgroundTaskCompleted;
        }
        catch 
        {             
            UnregisterBackgroundTask();
        }
    }

    private bool UnregisterBackgroundTask()
    {
        foreach (var iter in BackgroundTaskRegistration.AllTasks)
        {
            IBackgroundTaskRegistration task = iter.Value;
            if (task.Name == "PlaypushNotification")
            {
                task.Unregister(true);
                return true;
            }
        }
        return false;
    }

В моем файле манифеста

  <Extensions>
    <Extension Category="windows.backgroundTasks" EntryPoint="BackgroundTask.NotificationTask">
      <BackgroundTasks>
        <Task Type="pushNotification" />
      </BackgroundTasks>
    </Extension>
  </Extensions>

Триггер PushNotification не срабатывает, когда я отлаживаю, я обнаружил, что свойство триггера BackgroundTaskRegistration равно null. в чем проблема? Что здесь не так?


person Dattatray Deokar    schedule 30.03.2015    source источник
comment
есть ли кто-нибудь, кто может помочь по вышеуказанной проблеме?   -  person Dattatray Deokar    schedule 30.03.2015
comment
я думаю, что в фоновом режиме могут поддерживаться только необработанные уведомления, он отлично работает с необработанными уведомлениями   -  person Dattatray Deokar    schedule 30.03.2015