Windows Phone 8.1 Universal App, BackgroundTask is not running when trigger is set as Pushnotification -
i have created backgroundtask raw push notification , followed below steps. backgroundtaks not running when trigger set pushnotificationtrigger.
- i have created portable windows runtime component project.
create class mytask, here complete code of mytask class
namespace windowsruntimecomponent1 { public sealed class mytask : ibackgroundtask { public void run(ibackgroundtaskinstance taskinstance) { rawnotification rawnotification = taskinstance.triggerdetails rawnotification; } } }
added reference of windows runtime component project windows phone 8.1 universal app.
package.appxmanifest has below declaration
the backgroundtask registration has below code executes on click of button.
private async void registerbackgroundtask(object sender, routedeventargs e) { var access = await backgroundexecutionmanager.requestaccessasync(); if (access != backgroundaccessstatus.denied) { backgroundtaskbuilder builder = new backgroundtaskbuilder(); builder.addcondition(new systemcondition(systemconditiontype.internetavailable)); builder.name = "pushtasktest"; builder.taskentrypoint = typeof(windowsruntimecomponent1.mytask).fullname; builder.settrigger(new pushnotificationtrigger()); builder.register(); } }
code register pushnotificationchannel
protected async override void onnavigatedto(navigationeventargs e) { var channel = await pushnotificationchannelmanager.createpushnotificationchannelforapplicationasync(); notificationhub hub = new notificationhub( "testmobileservicehub", "endpoint=sb://testmobileservicehub-ns.servicebus.windows.net/;sharedaccesskeyname=defaultlistensharedaccesssignature;sharedaccesskey=wr6fstfuc+1ppnspujlcv3t57upfxlu="); var result = await hub.registernativeasync(channel.uri); }
now when running app, lifecycle events showing "no background tasks"
- but when put systemtrigger, lifecycle events showed up.
can 1 please why backgroundtask not running in case of push notification trigger?
Comments
Post a Comment