后台任务未注册,并且当应用程序在后台时代码不起作用

时间:2016-01-03 15:54:47

标签: parse-platform push-notification windows-phone-8.1 background-task

我使用解析来发送推送通知并且其工作正常但是,在后台,即,当应用程序未运行时,则执行注册后台服务的代码,但是没有设置任务和后台收到通知后不执行任务。请帮忙!!

以下是注册后台任务的代码

10,32,"Afghanistan","Afghanistan","Various organizations"  ..

在后台执行的代码:

Debug.WriteLine("Registering task");
                var taskRegistered = false;
                var exampleTaskName = "BackgroundTask";

                foreach (var task in BackgroundTaskRegistration.AllTasks)
                {
                    if (task.Value.Name == exampleTaskName)
                    {
                        taskRegistered = true;
                        task.Value.Unregister(true);
                        break;
                    }
                }

                await BackgroundExecutionManager.RequestAccessAsync();
                if (!taskRegistered)
                {
                    Debug.WriteLine("Registering task inside");
                    var builder = new BackgroundTaskBuilder();
                    builder.Name = exampleTaskName;
                    builder.TaskEntryPoint = "Tasks.BackgroundTask";
                    builder.Name = "PushNotification";
                    builder.SetTrigger(new Windows.ApplicationModel.Background.PushNotificationTrigger());
                    BackgroundTaskRegistration task = builder.Register();
                    await BackgroundExecutionManager.RequestAccessAsync();                        
                }

0 个答案:

没有答案